Petrucci Posted June 2, 2003 Posted June 2, 2003 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 Quote
Leaders dynamic_sysop Posted June 2, 2003 Leaders Posted June 2, 2003 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 Quote
Petrucci Posted June 2, 2003 Author Posted June 2, 2003 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) Quote
Leaders dynamic_sysop Posted June 2, 2003 Leaders Posted June 2, 2003 can you not Dim node as Object? then convert it to what you need? what are the items in the Structure? you must have them as something like Integer or String or something? Quote
Petrucci Posted June 2, 2003 Author Posted June 2, 2003 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 Quote
Administrators PlausiblyDamp Posted June 3, 2003 Administrators Posted June 3, 2003 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Petrucci Posted June 3, 2003 Author Posted June 3, 2003 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. Quote
Administrators PlausiblyDamp Posted June 3, 2003 Administrators Posted June 3, 2003 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? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.