Help with Byref or Byval for VB6

vb 6 , byref , byval Fort Wayne, United States
  • 8 years ago
    Hello, I'm very new to coding in VB6 and I need help. I have found documentation on using the Byref and Byval kewwords but I can't get my project to work. What I'm trying to do is to take the value of a string from one process and use that string in a second process. Then I would like to take a string from the second process and take the value back to the first process. Here is an example: Public Sub getadj(ims As SessionBox, byref **Editkeyfound** as string) Dim editkey as string **Editkey** = “636” Geteditcheck form1.imssession, (editkey) if **editkeyfound** = “Y” then.... End if End Sub Public Sub geteditcheck(ims As SessionBox, Byval **editkey** As String ) Dim editkeyfound as string Dim editot as string If editot = **EditKey** then **Editkeyfound** = “Y” else **Editkeyfound** = "N" End if End Sub Currently the string, editkey, will be recognized by the geteditcheck process. But the Editkeyfound from the geteditcheck process is not recognized by the getadj process. I know that I need to tell VB what Editkeyfound means but I can't get it to work using the byref or byval keywords. If I use these key workds just like I have with the Editkey string it returns a blank even though I hit the code that states it should be a "Y" or an "N". Please let me know if you can help me figure out why the editkeyfound string is not passing a value to the getadj process. Thanks!
  • 8 years ago
    In your code Public Sub geteditcheck(ims As SessionBox, Byval editkey As String ) Dim editkeyfound as string Dim editot as string editkeyfound is a local variable and its *scope* is geteditcheck. It can't be "seen" outside geteditcheck unless you return it somehow, and in your case, you would use ByRef variable. Change the code a bit: Public Sub geteditcheck(ims As SessionBox, Byval editkey As String, ByRef editkeyfound as string) Dim editot as string Now you can refer to editkeyfound parameters value outside your procedure. Teme64 @ [Link Text]( Windows Developer Blog

Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The question of whether computers can think is just like the question of whether submarines can swim.” - Edsger W. Dijkstra