Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET General > compiler out of compiler - declaring variables using array


Reply
 
Thread Tools Display Modes
  #1  
Old 03-04-2007, 06:54 PM
slowchem slowchem is offline
Newcomer
 
Join Date: Sep 2006
Posts: 8
Default 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
Reply With Quote
  #2  
Old 03-04-2007, 09:43 PM
jo0ls jo0ls is offline
Senior Contributor

Forum Leader
* Expert *
 
Join Date: Feb 2005
Location: London
Posts: 1,050
Default

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"
Reply With Quote
  #3  
Old 03-05-2007, 11:00 AM
slowchem slowchem is offline
Newcomer
 
Join Date: Sep 2006
Posts: 8
Default

Quote:
Originally Posted by jo0ls View Post
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
Reply With Quote
  #4  
Old 03-05-2007, 01:04 PM
wayneph's Avatar
wayneph wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

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
Reply With Quote
  #5  
Old 03-09-2007, 01:34 AM
slowchem slowchem is offline
Newcomer
 
Join Date: Sep 2006
Posts: 8
Default

Quote:
Originally Posted by wayneph View Post
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
Reply With Quote
  #6  
Old 03-09-2007, 08:19 AM
slowchem slowchem is offline
Newcomer
 
Join Date: Sep 2006
Posts: 8
Default

i get it now,
listbox1.items.insert(gotoy, additem)
and also the gotox part
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->