473,387 Members | 1,532 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

VB 6 Help with global variables

1
I have 2 forms the main form + a search form which is loaded when the user selects search from the menu of the main form..

in the code of the main form i have:

Public intindex As Integer

in my search form i have the following function :

Private Sub LstList1_Click() 'GO BACK TO PARENT FORM
intindex = LstList1.ListIndex
Unload Me
frmCourseManager.Visible = True
End Sub

when i compile the program i get the following error message :

Compile Error Variable not Defined - intindex

i know when i last ran the program in 2000 it worked fine but now i get the above error could this be a compatability problem ?
it worked fine in 2000 with windows 98 but now im using windows xp

thanks in advance.....
Jan 30 '06 #1
7 14206
It has got something to do with compatibility, i had this problem myself.
However, this was because i hadn't Dim'd the variables i had put into the script.

As far as i can tell, this problem is caused because you defined Intindex on a different form to the one that accesses it.
I found a way to fix this but can't for the life of me remember what it was.

Aha! This is a possibility:
When the form Unloaded itself, it may have lost the data it held (i.e Intindex)
I would suggest TRYING Instead of using:

Unload Me

use

SearchForm.Hide
(presuming you replace search form with the name OF your search form :p

I really hope this helps in some way :)
Sorry if it doesn't, i hope you solve your problem
Sep 3 '06 #2
Hemant Pathak
92 Expert
Hi.....................

Define ur public variable in the Module.

or remove the tag of Option Explicit in the top of ur form.
Sep 4 '06 #3
Hi,

From what I saw, you have declared a variable named intindex in lets say frmMain and are accessing it in the form named frmSearch.

Since you have declared the variable in the form module that is frmMain, it is accessible to the procedures written in frmMain only even if it is declared as Public. Insert a Standard Module and then declare this variable as Public there. It will be available to all the forms in your project.

I have 2 forms the main form + a search form which is loaded when the user selects search from the menu of the main form..

in the code of the main form i have:

Public intindex As Integer

in my search form i have the following function :

Private Sub LstList1_Click() 'GO BACK TO PARENT FORM
intindex = LstList1.ListIndex
Unload Me
frmCourseManager.Visible = True
End Sub

when i compile the program i get the following error message :

Compile Error Variable not Defined - intindex

i know when i last ran the program in 2000 it worked fine but now i get the above error could this be a compatability problem ?
it worked fine in 2000 with windows 98 but now im using windows xp

thanks in advance.....
Sep 21 '06 #4
Dear sir
When i compile the visual form iam getting the "compile error variable defined" error, please give the solution for this error






Thanks & Regards

Dhananjay babu.
Oct 14 '06 #5
when you decare a public variable in one form and use it in another form you must use FormName.VariableName to find the varialbe from another form.
Nov 17 '06 #6
albertw
267 100+
when you decare a public variable in one form and use it in another form you must use FormName.VariableName to find the varialbe from another form.
therefore you should declare variables which are used in severals forms in a module.
then make them 'public' or global (const)
Nov 18 '06 #7
This is THE best solution ever!
I had a different, yet similar problem with global variables.
They lost their value after an unknown period of time, but I declared them inside the same module as all my code.

My project got entirely undermined, since my global variable held the IRibbonUI reference to the WORD 2007 ribbon.
By putting all global (public) variables in a seperate module, they are more easy to find and their behaviour is more stable.


Thank you.
Aug 29 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: sarmin kho | last post by:
Hi Pythoners, i have been using a lot of global variables in the python script i am working on. the global variables are shared and used by all various 'definitions' : def name (): global all...
1
by: php newbie | last post by:
Hello, I am porting a stored procedure from Oracle. It uses a variable that remembers its previous values from each invocation. (It uses a PRAGMA REFERENCES clause for those who are familiar...
2
by: Henrik Thomsen | last post by:
hi ng I got two huge problems: 1) I have made a database that saves a users username a public variable when the database opens. When the database is shot down I wan't to save the time the...
5
by: Lian | last post by:
Hello Everybody I am writing a web application using c#. I have several pages. I want to create an Arraylist in one page fill it up and try to modify it in another page. How do I do it? ...
9
by: Ed Jensen | last post by:
I'm having a vexing problem with global variables in Python. Please consider the following Python code: #! /usr/bin/env python def tiny(): bar = for tmp in foo: bar.append(tmp) foo = bar
17
RobH
by: RobH | last post by:
I know its probably been asked a million times - however I can't seem to get any examples to work.. In Module1 I have a line: Global gvarMyEmpID As Integer I then have an opening splash page...
1
by: phoenix917 | last post by:
I have been working on this code for 5 days... I have read multiple tutorials and looked at various code. This is my third forum try... :) My instructor refuses to help me. I think it's because...
22
by: raashid bhatt | last post by:
Hi. Consider the Following Code. ========================================================================= #include <stdio.h> #include <string.h> /* For these Variables The Linker Only...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.