Im trying to create a 7 segment display for a project in visual basic 2005 express edition. I have a 2 dimentional boolean which stores the values of each of the segments for a certain display. I have written a case statement for the first display and would like to use it for the other displays instead of having to copy the code. I have tried everything I can think of but can't get it to pass the name of the boolean array im trying to set the values to from my main code to the procedure. Here is the code im passing: - For i As Integer = 1 To Len(CStr(Number)) Step 1
-
Dim MidString As String
-
MidString = CStr(Number)
- GetValues("VisPPL", Mid(MidString, (Len(MidString) - i + 1), 1), i)
-
Next i
The "VisPPL" is the name of the boolean array im trying to set the values to.
Here is the code from the start of my procedure my procedure: - Public Sub GetValues(ByVal VarName As ????, ByVal Number As Integer, ByVal Row As Integer)
-
-
Select Case Number
-
-
Case 0
-
VarName(Row, 1) = True
-
VarName(Row, 2) = True
-
VarName(Row, 3) = True
-
VarName(Row, 4) = False
-
VarName(Row, 5) = True
-
VarName(Row, 6) = True
-
VarName(Row, 7) = True
Ive tried using a string where the ???? is as the datatype for the name of the boolean array and im simply trying to get the VarName to be replaced with my boolean name (VisPPL) which im passing to it so I can pass different boolean arrays to the same procedure and it will set the values to that array.
Im not sure if I have explained my problem very well but any help is greatly appreciated.
Thanks, James
13 2322
... - Public Sub GetValues(ByVal VarName As ????, ByVal Number As Integer, ByVal Row As Integer)
-
-
Select Case Number
-
-
Case 0
-
VarName(Row, 1) = True
-
VarName(Row, 2) = True
-
VarName(Row, 3) = True
-
VarName(Row, 4) = False
-
VarName(Row, 5) = True
-
VarName(Row, 6) = True
-
VarName(Row, 7) = True
Use ByRef, instead of ByVal, i'd say something like this will do - Public Sub GetValues(ByRef VarName, ByVal Number As Integer, ByVal Row As Integer)
-
dim i as integer
-
select case number
-
case 0
-
for i = 1 to 7
-
varname(row,i)=true
-
next
-
varname(row,4)=false
-
case 1
-
....
This way, the variable will be called VarName inside the sub, but as you change VarName, you'll be changing the reference too.
HTH
Thanks that worked great. I have another question, at the moment I have to declare the values of each of my segments in reference to the array in the follow way: -
ltrTop1.Visible = Segs(2, 3, 1)
-
ltrTopL1.Visible = Segs(2, 3, 2)
-
ltrTopR1.Visible = Segs(2, 3, 3)
-
ltrMid1.Visible = Segs(2, 3, 4)
-
ltrBotL1.Visible = Segs(2, 3, 5)
-
ltrBotR1.Visible = Segs(2, 3, 6)
-
ltrBot1.Visible = Segs(2, 3, 7)
-
-
ltrTop2.Visible = Segs(2, 2, 1)
-
ltrTopL2.Visible = Segs(2, 2, 2)
-
ltrTopR2.Visible = Segs(2, 2, 3)
-
ltrMid2.Visible = Segs(2, 2, 4)
-
ltrBotL2.Visible = Segs(2, 2, 5)
-
ltrBotR2.Visible = Segs(2, 2, 6)
-
ltrBot2.Visible = Segs(2, 2, 7)
-
-
ltrTop3.Visible = Segs(2, 1, 1)
-
ltrTopL3.Visible = Segs(2, 1, 2)
-
ltrTopR3.Visible = Segs(2, 1, 3)
-
ltrMid3.Visible = Segs(2, 1, 4)
-
ltrBotL3.Visible = Segs(2, 1, 5)
-
ltrBotR3.Visible = Segs(2, 1, 6)
-
ltrBot3.Visible = Segs(2, 1, 7)
-
I was hoping to change this to something more like -
-
For i As integer = 1 to 3 Step 1
-
-
ltrTop"i".Visible = Segs(2, (4 - "i"), 1)
-
ltrTopL"i".Visible = Segs(2, (4 - "i"), 2)
-
ltrTopR"i".Visible = Segs(2, (4 - "i"), 3)
-
ltrMid"i".Visible = Segs(2, (4 - "i"), 4)
-
ltrBotL"i".Visible = Segs(2, (4 - "i"), 5)
-
ltrBotR"i".Visible = Segs(2, (4 - "i"), 6)
-
ltrBot"i".Visible = Segs(2, (4 - "i"), 7)
-
-
Next
-
-
But, I cannot get it to work. Once again thanks for all the help its greatly appreciated. I have been racking my brains on how to tackle this 7 segment display and I just feel there should be a simpler way to go about things but I cannot think of one, it doesn't help that i'm new to visual basic with a background in PHP which i thought would help but its proving not so.
Thanks, James
...
I was hoping to change this to something more like -
-
For i As integer = 1 to 3 Step 1
-
-
ltrTop"i".Visible = Segs(2, (4 - "i"), 1)
-
ltrTopL"i".Visible = Segs(2, (4 - "i"), 2)
-
ltrTopR"i".Visible = Segs(2, (4 - "i"), 3)
-
ltrMid"i".Visible = Segs(2, (4 - "i"), 4)
-
ltrBotL"i".Visible = Segs(2, (4 - "i"), 5)
-
ltrBotR"i".Visible = Segs(2, (4 - "i"), 6)
-
ltrBot"i".Visible = Segs(2, (4 - "i"), 7)
-
-
Next
-
-
Thanks, James
No, in VB you cannot do that with the names of the objects. But if they're controls in a Form, you can call them from the controls collection, using their name as a string.
Lets say you have your form called Form1, then something like this will do: - dim i as integer
-
For i = 1 to 3
-
form1.controls("ltrTop" & i).visible = segs(2, 4-i , 1)
-
form1.controls("ltrTopL" & i).visible = segs(2, 4-i,2)
-
'... and so on
-
next
HTH
Thanks, I have it set up like this but im still getting an error: -
For i3 As Integer = 1 To 5 Step 1
-
Me.Controls("salTop" & i3).Visible = Segs(3, (6 - i3), 1)
-
Me.Controls("salTopL" & i3).Visible = Segs(3, (6 - i3), 2)
-
Me.Controls("salTopR" & i3).Visible = Segs(3, (6 - i3), 3)
-
Me.Controls("salMid" & i3).Visible = Segs(3, (6 - i3), 4)
-
Me.Controls("salBotL" & i3).Visible = Segs(3, (6 - i3), 5)
-
Me.Controls("salBotR" & i3).Visible = Segs(3, (6 - i3), 6)
-
Me.Controls("salBot" & i3).Visible = Segs(3, (6 - i3), 7)
-
Next i3
-
-
For i2 As Integer = 1 To 5 Step 1
-
Me.Controls("ltrTop" & i2).Visible = Segs(2, (4 - i2), 1)
-
Me.Controls("ltrTopL" & i2).Visible = Segs(2, (4 - i2), 2)
-
Me.Controls("ltrTopR" & i2).Visible = Segs(2, (4 - i2), 3)
-
Me.Controls("ltrMid" & i2).Visible = Segs(2, (4 - i2), 4)
-
Me.Controls("ltrBotL" & i2).Visible = Segs(2, (4 - i2), 5)
-
Me.Controls("ltrBotR" & i2).Visible = Segs(2, (4 - i2), 6)
-
Me.Controls("ltrBot" & i2).Visible = Segs(2, (4 - i2), 7)
-
Next i2
-
-
-
For i As Integer = 1 To 5 Step 1
-
Me.Controls("pplTop" & i).Visible = Segs(1, (5 - i), 1)
-
Me.Controls("pplTopL" & i).Visible = Segs(1, (5 - i), 2)
-
Me.Controls("pplTopR" & i).Visible = Segs(1, (5 - i), 3)
-
Me.Controls("pplMid" & i).Visible = Segs(1, (5 - i), 4)
-
Me.Controls("pplBotL" & i).Visible = Segs(1, (5 - i), 5)
-
Me.Controls("pplBotR" & i).Visible = Segs(1, (5 - i), 6)
-
Me.Controls("pplBot" & i).Visible = Segs(1, (5 - i), 7)
-
Next i
-
The error can be seen here: http://www.jamesbuckland.com/garage/error.jpg
The controls im changing are image boxes is this why it will not work? Sorry for all the questions and thanks for all the help.
Thanks, James
Thanks, I have it set up like this but im still getting an error:
...
The error can be seen here: http://<br />
http://www.jamesbuckl...rage/error.jpg
Thanks, James
when this error occurs, pass the mouse over i3 (anyone) to see its current value at that moment.
its because saltop1 or saltop 2 or... does not exist, or because segs(3,5,1) or segs(3,4,1) or segs(3,3,1).... is not defined, or has not been set to a value or is not a boolean.
But that code you wrote, seems all right to me.
Only the first loop gets a value and the i3 is 1, ive looked over all the naming and it all looks fine. How can I give a value to every space in my array? Will this help?
Thanks, James
Only the first loop gets a value and the i3 is 1, ive looked over all the naming and it all looks fine. How can I give a value to every space in my array? Will this help?
Thanks, James
They already have one, it's 'False' by default.
the only thing that comes to my mind is:
what kind of control is salTop1?? i mean, is it a command button, or a combo box, or what is it?.
Or pass the mouse over Segs (any of them) when the error occurs, and check its values. Check if Segs(3, 5, 1) has a boolean's value (true or false)
salTop1 etc. are Pictures Box's with an image of a segment in them. I can change them to something else if it will help.
Thanks, James
salTop1 etc. are image box's with an image of a segment in them. I can change them to something else if it will help.
Thanks, James
No no, image boxes does have the visible property, ... and what about the boolean's value? is it set to True or False?
other thing that comes to my mind is that maybe the image boxes have another parent, like a frame.
so you might need to put the complete 'path': - me.frame1.controls("something" & i).visible = true.
They all seem to have values:
Thanks, James
Thank you so much. My stupid mistake i had them in a group box for visual effect and once i added the name for the groups it worked perfectly. Thanks for all the help I really appreciate it and im sure I can only learn from my mistakes.
Thanks, James
Thank you so much. My stupid mistake i had them in a group box for visual effect and once i added the name for the groups it worked perfectly. Thanks for all the help I really appreciate it and im sure I can only learn from my mistakes.
Thanks, James
L O L, dont be so rude with that poor mistake.
im glad it helped you.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Ken Halley |
last post by:
How does one refer to a variable name using a variable within a variable
name??? For example, I want to perform a SQL query and use the results of
the query to determine which variable to assign a...
|
by: Jas |
last post by:
Hi All
I guess I should just have tried this to see if it works but I don't have
access to a machine running IIS and can't test it and I am itching for an
answer.
I want to use dynamic...
|
by: firegun9 |
last post by:
Hello all,
After looking for the solution for a while in the group, I know this is
not possible in C++. So I just say my problme here.
The input file is:
dev1 1 1
dev2 0 0 0 6
There is a...
|
by: Tim.D |
last post by:
People,
I've ventured into the wonderful world of Stored Procedures. My first
experience has been relatively successful however I am stuck on using
host variables to specifiy actualy table or...
|
by: serge |
last post by:
How can I run a single SP by asking multiple sales question either
by using the logical operator AND for all the questions; or using
the logical operator OR for all the questions. So it's always...
|
by: Mark S. |
last post by:
As I understand it, C# doesn't offer dynamic variable names. Below is my
attempted workaround. Is what I'm doing possible?
FYI, I already read all the "why in the world do you need dynamic...
|
by: Rolf Mander |
last post by:
Hi,
I need to use dynamic variable names but for objects.
As you know something like that works fine:
$variable="content";
$part="able";
echo ${"vari".$part};
// gives out content
but i...
|
by: DavidSeck.com |
last post by:
Hi guys,
first post :)
my question: is it possible to have dynamic variable names, I mean
something like this:
for($i=0;$i<x;$i++){
$y_$i = blabla;
}
|
by: JamieHowarth0 |
last post by:
I'm about to set up a new website, powered by DotNetNuke (my favourite CMS at the moment, mainly because it's free), and I want to install a Counter-Strike game server onto the same machine. I also...
|
by: Aaron \Castironpi\ Brady |
last post by:
Hello all,
To me, this is a somewhat unintuitive behavior. I want to discuss the
parts of it I don't understand.
.... f= lambda: n
....
9
9
|
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...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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,...
|
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...
| |