Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

VB has just gone weird

Posted on 2003-03-06
9
Medium Priority
?
136 Views
Last Modified: 2010-05-01
Hi,

Somehow every local, global and module level string variable in my program (even the Connection String Property of the ADO Connection object!) is getting set to the same SQL Query string.  

The SQL query is built in a function, assigned to a local variable, then passed back to another function which executes it.  If I step through it all works fine, if I try to run through it errors because the check;

If strOrder_By <> "" Then ...(add the order by clause)

Hovering over and debug printing strOrder_By says it equals "" but when VB evaluates this line it runs the Then statement???

The really crazy thing is if I hit End on the error message window, then re-run the program... every string is still set to the last SQL Query, sames as when I stopped the prog.  I have to re-start VB to get it to run again, rebooting PC has no effect.

With the same code this is doing the same thing on both of my machines (VB6 SP5).  Am I going mad or have you guys seen this kind of insanity before?

Please Help if you can,

North
0
Comment
Question by:North
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 7

Expert Comment

by:fluglash
ID: 8078973
try to replace "" with vbNullString
0
 
LVL 55

Expert Comment

by:Ryan Chong
ID: 8078993
In your function, try use the ByVal rather than using default ByRef (VB6).

So, define your function like this:

function generateSQL(byval table As String,byval flds As String,byval condition As String, byval orderby As String, byval orderbyfld As String) As String
  generateSQL = "Select " & flds & " from " & table " & condition & IIF(orderby <> "",orderby & " " & orderbyfld,"")
end function
0
 
LVL 7

Expert Comment

by:fluglash
ID: 8079013
Strings in VB using ByVal by default
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:North
ID: 8079049
Hi,

Yeah I tried that fluglash, but it seems a little stranger than that, for example, when it reloads I set a function parameter to the result of an ini read (my data source cfg file).  Once inside the function, the parameter = the contents of the ini file + the SQL query from the previous execution, crazy isn't it!

ryancys, cheers for that, but it is more or less what it is doing already.  I have module level Private variables and use property lets to set them, you then call an execute method which builds the SQL from the current state of the properties.  It means that all knowledge of the database and SQL queries is handled outside of the main interface code.  

I now have actually solved this by making a new project file and including all components and references then adding all my forms, etc.  The only strange thing I got was a message from each form that uses an OCX of mine, saying the GUID ref was invalid, but it still found and used the controls in the OCX I had included in the new VBP.  I think the old VBP somehow got corrupted and had some weird reference?

The points are still there if anyone can tell me why it happened? Note: When I copy the code from my desktop to my laptop, and vice-versa, I have to recompile the OCX (binary compatability) or the program doesn't recognise the old OCX in the system32 folder, i then have to load the prog, add the recompiled ocx as a component, close and save only the project file, then reopen.  Could this be the cause and is there a better way?

North

0
 
LVL 55

Accepted Solution

by:
Ryan Chong earned 800 total points
ID: 8079344
>>, the parameter = the contents of the ini file + the SQL query from the previous execution, crazy isn't it!

I think maybe you forget to clear its value when assign it with the value in ini file. Try set the variable to "" before re-assign it with an value. Try to break the code (with F9) to debug your code, it do make helps.
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 8079589
Try this


If format(strOrder_By) <> "" Then
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 8079602
Sorry forget my comment


8->
0
 
LVL 1

Author Comment

by:North
ID: 8080627
Hi ryancys,

Assigning the variable the value from the ini file is the first thing I do after the program starts, it should be defaulted to "".  I never set that particular variable to the value of the SQL statement, every string variable in the program magically gets that value from nowhere once it has gone weird.  Most importantly, even after stopping and restarting execution.  It must be some strange memory, pointer or reference issue.

The problem is now solved by recreating the VBP file, I was just wondering if repeatedly swapping the code to run on one machine to another one where the dependent OCX has different GUIDs could be the cause?

North
0
 
LVL 1

Author Comment

by:North
ID: 8102646
Hi,

though there was no clear solution to my problem, I hate leaving questions open or asking CS to delete them when people have tried to help.  I have chosen ryancys' comment, on volume and relevance of comments.

Cheers for trying guys,

North
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month13 days, 7 hours left to enroll

579 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question