Hi,
I am having problem to retrieve the data value of a public variable. Below is my code:
Form1 - Option Explicit
-
Public selected_entry_id As String
-
-
Private Sub btnEdit_Click()
-
selected_entry_id = DataGrid1.Columns(0)
-
Form2.Show
-
End Sub
-
-
Private Sub DataGrid1_Click()
-
selected_entry_id = DataGrid1.Columns(0)
-
End Sub
Form2 - Private Sub Form_Load()
-
-
If selected_entry_id = "" Then
-
MsgBox "Empty"
-
Else
-
MsgBox "Value exists"
-
End If
-
-
lblselectedid.Caption = selected_entry_id
-
-
End Sub
I keep reveceiving empty value for the public variable (selected_entry_id).
May i know what is the mistake from my code above?
6 1729
Try this line instead:
[PHP]lblselectedid.Caption = Form1.selected_entry_id[/PHP]
Good Luck.
Try this line instead:
[PHP]lblselectedid.Caption = Form1.selected_entry_id[/PHP]
Good Luck.
That or make the actual variable global, for example put the variable into the a Module (.bas) that way the variable is there when the Application is launched and is created in runtime, were as for example if you unloaded form1 and loaded form2 you would have lost any data in that variable, until you reloaded form1 and put data back into it, but thats only if you are trying to pass data between a lot of forms, it can make things easier than trying to go Form1.Label1.Caption for about 10 different captions.
But hope thats a bit more insight
Kind Regards
Devon.
A variable declared as Public within a Form only exists within that form (as you would have seen if you had specified Option Explicit in Form2). You can access it by specifically referencing the form, as iburyak has shown.
If you want global variables that you can use anywhere in your project, declare them as Public in a code module.
I always recommend the use of Option Explicit, as it prevents exactly this sort of problem by allowing you to use only those variables you have explicitly created. In this case, since you referenced a non-existent variable selected_entry_id in Form2, VB helpfully created it for you. But of course, it didn't contain anything.
A variable declared as Public within a Form only exists within that form (as you would have seen if you had specified Option Explicit in Form2). You can access it by specifically referencing the form, as iburyak has shown.
If you want global variables that you can use anywhere in your project, declare them as Public in a code module.
I always recommend the use of Option Explicit, as it prevents exactly this sort of problem by allowing you to use only those variables you have explicitly created. In this case, since you referenced a non-existent variable selected_entry_id in Form2, VB helpfully created it for you. But of course, it didn't contain anything.
Hi,
How to declare the variable in a code module?
How to declare the variable in a code module?
Create a code module, and put your Public statement in it.
If you don't know how to create a code module, you need to read the documentation.
Hi,
I am having problem to retrieve the data value of a public variable. Below is my code:
Form1
======
Option Explicit
Public selected_entry_id As String
Private Sub btnEdit_Click()
selected_entry_id = DataGrid1.Columns(0)
Form2.Show
End Sub
Private Sub DataGrid1_Click()
selected_entry_id = DataGrid1.Columns(0)
End Sub
Form2
=====
Private Sub Form_Load()
If selected_entry_id = "" Then
MsgBox "Empty"
Else
MsgBox "Value exists"
End If
lblselectedid.Caption = selected_entry_id
End Sub
************************************************** ********************************
I keep reveceiving empty value for the public variable (selected_entry_id).
May i know what is the mistake from my code above?
pls explain ur flow of execution
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Vinay Aggarwal |
last post by:
I have been thinking about the lazy initialization and double checked
locking problem. This problem is explain in detail here
http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html...
|
by: Stephen Cook |
last post by:
Having worked through the problems around enabling the document function
using an XmlUrlResolver I started work on building a useful class to hide
the intricacies.
Trying to generalise the process...
|
by: Mark |
last post by:
Hi all,
i'm trying to serialize a class. Using the constructor of
XmlSerializer i get these (odd?) errors: "File or assembly name
goseij9w.dll, or one of its dependencies, was not found"....
|
by: Rhy Mednick |
last post by:
I'm creating a custom control (inherited from UserControl) that is displayed
by other controls on the form. I would like for the control to disappear
when the user clicks outside my control the...
|
by: Lokkju |
last post by:
I am pretty much lost here - I am trying to create a managed c++
wrapper for this dll, so that I can use it from c#/vb.net, however, it
does not conform to any standard style of coding I have seen....
|
by: Philip Tepedino |
last post by:
I'm having an odd problem. My website's session state is getting shared
between users!
This problem only happens when a user tries to access the site from inside
our corporate LAN. The user,...
|
by: garyusenet |
last post by:
This is the first time i've worked with openfile dialog.
I'm getting a couple of errors with my very basic code.
Can someone point out the errors in what i've done please....
|
by: tshad |
last post by:
In VS 2003, I am setting up an abstract class that is setting up classes for
each datatype of VB.Net (as well as C#).
I am trying to set it up so that most of the work is done in the Abstract...
|
by: edsunder |
last post by:
I'm making a "wrapper" for an unmanaged DLL (written, I'm fairly certain in C). I have a c++ "wrapper" that I'm trying to convert to VB.net. I've got most of the program working, but I've hit a brick...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
| |