VB .NET late Dim problem

Petrucci

Newcomer
Joined
Jun 2, 2003
Messages
4
Hi, I want to convert several Functions in VB .NET to one.
For that i need to make a late Dim but I can't get it to work.
I always get compile errors...
It is a simple search and return position in a file.
If anyone knows how to fix it it would be great.

Here's the code NOT working(but gives you the idea of what i want):

Code:
Public Function Get_   (ByVal nome As String, ByVal type As String)

        Dim posi As Short

        Select Case type
            Case "pizzas"
                Dim node As node_pizza
                file = 1
            Case "drinks"
                Dim node As node_drinks
                file = 2
        End Select

        FileGet(file, node, 1)
        posi = node.next
        FileGet(file, node, posi)
        While (posi<> 1 AndAlso String.Compare(Trim(node.name), name) <> 0)
            posi = node.next
            FileGet(file, node,posi)
        End While

        Return   posi

End Function

node_pizza and node_drinks are structures

Thanks
 
Visual Basic:
Public Function Get_   (ByVal nome As String, ByVal type As String)

        Dim posi As Short
        Dim node As String '/// make it a string or what you want first
        
        Select Case type
            Case "pizzas"
                node = node_pizza
                file = 1
            Case "drinks"
                node = node_drinks
                file = 2
        End Select

        FileGet(file, node, 1)
        posi = node.next
        FileGet(file, node, posi)
        While (posi<> 1 AndAlso String.Compare(Trim(node.name), name) <> 0)
            posi = node.next
            FileGet(file, node,posi)
        End While

        Return   posi

End Function
 
Thanks but you got it wrong...

I can't make node as string. It must be something that i can convert later to type node_pizza or node_drinks.
The way you corrected wouldn't allow me to use node.next for example (next is not a member of String)
 
I've already tryed that but got a "Security Error" in FileGet(file, node, 1)

i tryed this:

dim node as object
....
node = ctype(node,node_pizza)
....


the structure pizza is
Code:
    Structure node_pizza
        <VBFixedString(20)> Dim name As String
        Dim price As Single
        Dim first_ing As Short
        Dim next As Short
    End Structure

I must be doing something wrong
 
What is the FileGet function doing? If you step through the code does it fail within the FileGet routine?

Also if the two structures node_drinks and node_pizza have a common set of functions you may want to investigate Interfaces as a possible way of solving the problem.
 
The FileGet gets the info from the file at given posicion and puts it to the "structure" node.
Yes, it fails even if I step through it and I can't use interfaces.
 
Does it fail on a particular line or lines. do you have permissions to the file you are trying to read? Also is the file local or on a network share?

ps. any particualr reason why you can't use interfaces?
 
Back
Top