Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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):

 

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

  • Leaders
Posted
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

Posted

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)

Posted

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

   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

  • Administrators
Posted

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...