DIGIT-ARC read-only archive · snapshot: July 23, 2026

Visual Basic programming question

9 posts · originally from https://geek.digit.in/community/threads/visual-basic-programming-question.5688/

S
sohummisra Original post #1
Feb 14, 2005 at 10:47 AM
I'm using VB6 to make this program and I have this minor problem that is very difficult to search for on the net (because the solution is so simple--I just don't know it or it is eluding me). Basically I have a public procedure which contains a parameter. Let's just call it:

Code:
Public Sub X(Byval username As String)
     blah blah
End Sub

Now I want to use the same parameter in a user-generated click event on a command-button. I was wondering if there is anyway to refer to that variable (in the the Sub X) from within the other procedure and how to do this. I was trying things like X.username but it didn't work. :S[/code]
tuxfan
tuxfan #2
Feb 14, 2005 at 11:40 AM
sohummisra said:
Now I want to use the same parameter in a user-generated click event on a command-button. I was wondering if there is anyway to refer to that variable (in the the Sub X) from within the other procedure and how to do this. I was trying things like X.username but it didn't work. :S

Could you just clarify a little more. What exactly do you want to do?

x.username would surely not work because s is not an object, its just a procedure (sub-routine). What you can do is have a global variable having the same value as username and access that on the click event.
D
daj123 #3
Feb 14, 2005 at 3:04 PM
lol, the answer is quite simple. You either set a global variable when that 'sub X' is called.

Code:
Option Explicit
Public myusername as STRING

Public Sub X(Byval username As String)
     myusername = username
End Sub 

Public Sub AnotherX
     command1.text = myusername
End Sub

Hope you get the idea ;)
S
Feb 14, 2005 at 5:03 PM
I know that the problem can be solved using a global variable but I was wondering if there was any way to program it without 'wasting' space. That is, programming it efficiently yet confusingly. A global variable would solve all problems because then variables would not have to be passed.
tuxfan
tuxfan #5
Feb 14, 2005 at 9:00 PM
Actually, there could be a better way then making a global variable. Just tell us exactly what you are trying to do and what is the purpose of accessing that variable. We need more details.
S
Feb 15, 2005 at 5:44 PM
Okay basically I am making a sort of organizer program for my IB Computer Science class. Since the user requires to login with the username and password, and the username is used to access all of the user's files, it is a variable that is required by more or less all the procedures and functions. This was no problem in pseudocode because user-generated procedures were not differentiated.

Now, I have made an Add Activity form which opens and shows. Unfortunately, this requires me to use a Command_Click() function which does not have the username parameter because the latter is not a global variable. But the AddActivity procedure in the add activity form needs the username parameter. Any more questions? Please do ask.
tuxfan
tuxfan #7
Feb 16, 2005 at 2:45 PM
I think there is some fault in your designing. In Add if you need a username, create a variable.

If the same variable is earlier entered somewhere, it must be stored in a database table. Retrieve it from there!! If it is not there in the database, you will want your user to enter it. So get it in a textbox and take it from there!! What's the problem?

Frankly speaking, I am really not too sure what you are trying to do. Your design or logic seems to have some problem.
S
Feb 16, 2005 at 3:10 PM
I figured I don't really need it because I just needed it to open the files. There was no design logic problem--there was just the problem of transferring the username from a computer-process to a user-generated event.
tuxfan
tuxfan #9
Feb 17, 2005 at 11:17 AM
Good to know that there was no designing problem :) That could've increased a lot of problems for you. I felt there was a problem from your questions. :D