faid
faid

Reputation: 405

Use Object or String from other Sub VB6

How to make it's possible in vb6, for example i want to show result in Sub Action() and on Btn1_Click() but i set all required Object and String on Form_Load():

Private Sub Form_Load()
Dim ObjFso As Object
Dim TheText As String
Set ObjFso = CreateObject("Scripting.FileSystemObject")
TheText = "Hello"
Call Action
End Sub

Public Sub Action()
ObjFso.CreateTextFile("Test.txt").WriteLine(TheText)
MsgBox TheText, 0, "This is the text"
End Sub

Private Sub Btn1_Click()
If ObjFso.OpenTextFile("Test.Txt",1).ReadLine = TheText Then
MsgBox "Success", 64, "Ok"
Else
MsgBox "Fail", 16, "Ouch"
End If
End Sub

Upvotes: 0

Views: 505

Answers (1)

Rasel
Rasel

Reputation: 15477

There is no difference with any other modern language.

You can decalare 'Dim TheText As String' globally at the beginning of the form code.So you can access it in any Sub or Function of the form.

Also you can call CallAction like CallAction(theText) using as a parameter.Your CallAction sub will be

public sub CallAction(text as String)
msgbox text
end sub

Upvotes: 3

Related Questions