Closed Thread Icon

Topic awaiting preservation: Visual Basic - Conditions (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=26394" title="Pages that link to Topic awaiting preservation: Visual Basic - Conditions (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Visual Basic - Conditions <span class="small">(Page 1 of 1)</span>\

 
Skaarjj
Maniac (V) Mad Scientist

From: :morF
Insane since: May 2000

posted posted 08-06-2005 08:20

I know from my experiences in programming using PHP that i can do conditional statements like this one:

code:
$connection = @mysql_connect($host, $user, $pass) or die('Error in connecting to mySQL server');



I'm trying to achieve something like that in VB. What I have is an ADODB.RecordSet, several of them actually, each one working in conjunction with the others to retrieve a set of records form one table, find match equivilants in a second and, having compiled a string of them, depositing them into a third table. My problem is that if one of the record requests fails to retrieve a record becuase the field is empty then the whole sequence crashes. What I want to do is specify that, if this fails, don't show me an error message, instead put this other bit in its place. I'm not sure if this can be done in VB, but I'd swear I've seen something like it elsewhere. Anyone got any ideas?


Justice 4 Pat Richard

H][RO
Bipolar (III) Inmate

From: Australia
Insane since: Oct 2002

posted posted 08-06-2005 10:14

I have done a bit of vb, but it was a while back and i used to treat it "dumb" basically doing more complicated things manually - i.e you would need some if statements etc.

There is possibly a way to do it however I am just starting a new project in vb.net will let you know if i figure it out

Blacknight
Paranoid (IV) Inmate

From: INFRONT OF MY PC
Insane since: Dec 2001

posted posted 08-08-2005 14:43

try this one

try
$connection = @mysql_connect($host, $user, $pass)
catch
messagebox("Error in connecting to mySQL server")
end try

not sure if the syntax is correct but it looks something like this

_Mauro
Nervous Wreck (II) Inmate

From:
Insane since: Jul 2005

posted posted 08-08-2005 15:10

The "try catch" syntax is valid in Java, .net (C#) or c++, not in vb. In VB, you have the beautiful "On Error Resume Next"
to resume execution right after the error, or "On Error Goto flag", and later on, use a flag to "flag" the code you want to jump to,
like flag:

Or, "On Error Goto myMarker

...
some code
...

myMarker:
"

Blacknight
Paranoid (IV) Inmate

From: INFRONT OF MY PC
Insane since: Dec 2001

posted posted 08-08-2005 16:13

no i think the try cath syntax is valid since vb.net .. but i may be mistaken there

H][RO
Bipolar (III) Inmate

From: Australia
Insane since: Oct 2002

posted posted 08-08-2005 16:21

Yes you are correct blacknight, vb.net is substantially different - you also need a different mindset to the old VB since now its OOP...

code:
Sub DoSomething()
       Try
              'Do Something
       Catch e as Exception
              'Catch the error and display it.
              Response.Write ("An Error Occurred: " & e.toString())
       Finally
              'Do the final cleanup such as closing the Database connection
       End Try

End Sub

H][RO
Bipolar (III) Inmate

From: Australia
Insane since: Oct 2002

posted posted 08-08-2005 16:26

Oh vb.net still supports On Error etc, for compatibilty purposes - but you shouldnt use them for new stuff obviously...

Skaarjj
Maniac (V) Mad Scientist

From: :morF
Insane since: May 2000

posted posted 08-09-2005 00:13

Good thing I only have VB6.0 then, I guess. I can't afford the .NET Visual Studio just yet, so... thanks guys, this should help.


Justice 4 Pat Richard

H][RO
Bipolar (III) Inmate

From: Australia
Insane since: Oct 2002

posted posted 08-09-2005 05:45

Man get visual basic .net standard - i picked it up for $180 AUD retail version. You don't need visual studio to be able to do everything and for stuff that is done out of the box with VS there are workarounds for Standard.

H][RO
Bipolar (III) Inmate

From: Australia
Insane since: Oct 2002

posted posted 08-09-2005 05:50

Its quite annoying to be honest, they dont have an in-between version. I dont want visual c++, visual J etc but i do want to be able to make class files etc...

The major thing that is missing if all you are using is visual basic - is Crystal Reports. I havn't used them before anyway so i just make my own reports & word documents instead!

(Edited by H][RO on 08-09-2005 05:52)

« BackwardsOnwards »

Show Forum Drop Down Menu