 |
 |

03-04-2007, 06:54 PM
|
|
Newcomer
|
|
Join Date: Sep 2006
Posts: 8
|
|
compiler out of compiler - declaring variables using array
|
im trying to make a simple application that its like a compiler out of compiler...
got richtextbox where i put syntaxes/codes...
but i got problem with the declaration...
the only way i know to declare variables from my richtextbox to
my code is to use an array.. and then store it as array again
the syntax for my compiler out of compiler declaration:
DECLARE <DATA TYPE> <variable name>
ex: DECLARE NUMBER num1
Code:
Dim linesyntax() As String = line.Split(" ".ToCharArray)
Dim numberVariable() As Integer
Dim nv As Integer
nv = 0
Select Case linesyntax(0).ToUpper
Case "DECLARE"
Select Case linesyntax(1).ToUpper
Case "NUMBER"
numberVariable(nv) = linesyntax(2)
ListBox1.Items.Add(numberVariable(nv))
Case "ALPHABET" 'Char
Case "TRULSE" 'Boolean
Case "FLOATIMAL" 'decimal
End Select
Case "PRINT"
End Select
i got this error Unhandled exception of type 'System.NullReferenceException'
any tip how to fix this?
or are there any other way how to do what im trying to do?
thanks
|
|

03-04-2007, 09:43 PM
|
|
Senior Contributor
Forum Leader * Expert *
|
|
Join Date: Feb 2005
Location: London
Posts: 1,050
|
|
numberVariable isn't initialized, hence the error.
It's probably easier to use a List, rather than an array, as you won't know the size beforehand.
I think it cries out for a generic dictionary though:
Code:
Dim numbers As New Dictionary(Of String, Integer)
' DECLARE NUMBER X
numbers.Add("X", 0) ' add a dictionary entry, key = "X", value = 0
' X = 100
numbers("X") = 100
In vb2003 you could use a hashtable.
"TRULSE" 
|
|

03-05-2007, 11:00 AM
|
|
Newcomer
|
|
Join Date: Sep 2006
Posts: 8
|
|
Quote:
Originally Posted by jo0ls
numberVariable isn't initialized, hence the error.
It's probably easier to use a List, rather than an array, as you won't know the size beforehand.
I think it cries out for a generic dictionary though:
Code:
Dim numbers As New Dictionary(Of String, Integer)
' DECLARE NUMBER X
numbers.Add("X", 0) ' add a dictionary entry, key = "X", value = 0
' X = 100
numbers("X") = 100
In vb2003 you could use a hashtable.
"TRULSE" 
|
i got the idea of using dictionary and i tried your code
but the parameters (Of String, Integer) gives me an error..
and it's DictionaryEntry in VB.net
i tried searching google/books on how to use dictionary
but i cant get any info how to use it in vb.net...
can anyone give me a link? thanks
|
|

03-05-2007, 01:04 PM
|
 |
Web Junkie
Retired Moderator * Expert *
|
|
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
|
|
Quote:
|
Originally Posted by jo0ls
In vb2003 you could use a hashtable.
|
Or if you're using vb2005 then you need to make sure the right namespace is imported. Then the Dictionary will be available.
System.Collections.Generic
|
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
|

03-09-2007, 01:34 AM
|
|
Newcomer
|
|
Join Date: Sep 2006
Posts: 8
|
|
Quote:
Originally Posted by wayneph
Or if you're using vb2005 then you need to make sure the right namespace is imported. Then the Dictionary will be available.
System.Collections.Generic
|
thanks for the link, ill try to learn that later...
anyway, is it possible to add an item into a specific line in a listbox?
i'd tried search function but i cant find related about this question...
because i want to add a command "GOTOXY" like in C++
gotoxy(x,y)
where x = maybe spaces " " but using spaces it will erase all underneath it
and y = listbox line
thanks
|
|

03-09-2007, 08:19 AM
|
|
Newcomer
|
|
Join Date: Sep 2006
Posts: 8
|
|
|
i get it now,
listbox1.items.insert(gotoy, additem)
and also the gotox part
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|