Reputation: 405
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
Are it's possible when i press Btn1 i got "Success" Message Box?
Note: I ask this because i don't know about vb6 arguments like Call TheSub(arguments)
, i just know arguments in VBS but not in VB6, so please don't close this question :)
Upvotes: 0
Views: 505
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