What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » VB/Web Help

Pages: (2): « First « 1 [ 2 ] Last »
VB/Web Help
Author: Message:
Ezra
Veteran Member
*****

Avatar
Forgiveness is between them and God

Posts: 1960
Reputation: 31
37 / Male / Flag
Joined: Mar 2003
RE: VB/Web Help
quote:
Originally posted by DragonX
code:
System.Diagnostics.Process.Start(URLString)


I just thought about that :P, you were quicker :D

This post was edited on 10-05-2005 at 02:29 PM by Ezra.
[Image: 1-0.png]
             
10-05-2005 02:28 PM
Profile PM Web Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15517
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: RE: VB/Web Help
quote:
Originally posted by DragonX
What is the $ used for? I've never used it in a replace() before.
Almost every intristic string function in VB (note again: I'm talking about VB, not VB.NET!! It might be different in VB.NET) has two possible ways of use.
1) Firstly (and this is the one mostly used because people don't know any better) most of such functions are able to return a Variant data type.
2) Second, it can directly return a String data type.

Now... A Variant is a special kind of VB data type. It can actually hold all types of data types. In some cases, and used properly at given times, this can be very handy. But mostly, this just slows down your application _and_ is also the cause of many "hidden" errors in applications.

It is much slower because VB constantly needs to check what actual data type the variant is holding and it constantly needs to convert from variant to that data type in calculations, procedures, etc. The variant also uses extra memory (as it needs to hold extra information to identify the actual data type). Furthermore, a variant data type which is holding a number, actually has two data types assigned to it: firstly the number data type (can be integer, long, whatever) and second a string representing that number. Again extra memory and more slowness...

Important: If you have the bad habbit of not declaring variables, VB doesn't know what type you exactly are going to use in your program for that variable and thus reverts back to a variant data type.

The next code is perfect legal in VB:
code:
A = "Hello world"
MsgBox A
A = 1234
MsgBox A
First you assign a string to the variable A, next you assign a number. Since you didn't declare the variable A and thus didn't told VB what data type it is going to be, VB makes it a variant. And thus, that's why that code is valid.... but dead slow...
code:
Dim A As String
A = "Hello world"
MsgBox A
A = 1234
MsgBox A
This will result in an error on the line 'A = 1234' because you explicitly declared variable A as a String. A string can't be a number...

Now that you know what a Variant is and why you should avoid it at all costs, we come to those intristic string functions like Left(), Right(), Mid(), Format(), etc...

As said they have the possebility to return a Variant or directly return a String data type. If you attach $ (the symbol for a String data type) to the function's name, VB knows it should return a String instead of the default Variant data type.

The benefit is that VB doesn't need to convert the Variant (which it returns by default) to a String in calculations, procedures, assignments, etc...

Consider the next code:
code:
Dim A As String
Dim B As String
A = Mid("Hello World", 7, 1)
B = Mid$("Hello World", 7, 1)
VB performs the next things in the A assignment:
1) create the string "Hello World" in memory
2) jump to the 7th character and copy 1 character from that point on
3) create a new variant data type in memory and assign the previous 1 character string to it
4) try to convert that string to a numerical value and assign that also to the variant in memory
5) convert the variant data type to a string data type again
6) assign that new string to the string variable A

VB performs the next things in the B assignment:
1) create the string "Hello World" in memory
2) jump to the 7th character and copy 1 character from that point on
x) create a new variant data type in memory and assign the previous 1 character string to it
x) try to convert that string to a numerical value and assign that also to the variant in memory
x) convert the variant data type to a string data type again
3) assign that new string to the string variable A


This said, I just found out that the string function Replace() will actually always return a string, wether you use $ or not. At least that is what the syntax help tells me. I need to look deeper into this though, as I find this rather curious... So Mike, for now, you were actually wrong :p (and me too for saying you were totally correct :p)

-----------------------------------------

quote:
Originally posted by DragonX
quote:
Originally posted by CookieRevised
code:
Private Declare Function ShellExecute Lib "SHELL32" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Must i use the API ? Did it that way anyways, for now ;)
In VB (again, I'm not speaking about VB.NET), yes... VB also knows a Shell() function, but this is a very simplified version of the ShellExecute API and can only run real executables or associations. It can't run protocols like "http://"...

quote:
Originally posted by DragonX
code:
ShellExecute(0&, vbNullString, URLString, vbNullString, vbNullString, vbNormalNoFocus)
What is '0&' for ?
As I explaned in the previous post, when you call the ShellExecute API the first parameter is the handle to the window which will be the parent of the process you're going to start. If you set this parameter the process you're going to start is going to be a child process. In normal use of this API (to start some programs for example), this isn't needed and can even be not wanted. This means you must set this handle parameter to NULL (NULL = not used/nothing/not applicable/no valid data). But VB doesn't know the constant NULL (at least not for this purpose! Important: Do not use vbNull for this!!!!!!! vbNull is _not_ NULL, it is a constant to indicate a variant with no valid data and will actually return the value 1!!!!). In fact what is NULL? NULL is zero, so we set that parameter to 0. The & at the end is the sign for the Long data type. Again, so VB doesn't need to convert the Variant 0 to the Long data type but directly makes it a Long instead.

quote:
Originally posted by DragonX
Edit2: Alright, after some digging, i found out the KeyPress was redefined in .NET. And to make it work, u need code that looks like this[/code]Well, you asked for VB help, you got VB help :p not VB.NET help. Those two languages are different, as you just experienced ;)

quote:
Originally posted by DragonX
code:
(...)
ElseIf KeyAscii = 27 Then
    End
End If

Ohooooh.... Aiaiai... this is an oh-so-frequent error to make... Although it works, try to avoid crashing against the wall to stop the car!!! In plain English :p: do not use the End statement! 'End' immediatly stops your application without the decent cleaning up. This can cause serious errors like memory leaks, crashing, freezes and what not, if you don't know exactly what you're doing and you're using 'advanced' stuff as classes and objects... Instead, UNLOAD your main form _after_ you unloaded all your other (child) forms and have cleared all the used objects and have cleared all the used classes... This clearing up can best be done in the Unload event of a form. And to end your application, simply call/execute the unload event by unloading the main form.

As long as you don't use any asyncronical functions like DoEvents(), you actually do not need to use the End statement at all!!! And in most cases DoEvents is also something which can be avoided and is often a sign of a bad programming scheme. In case you do use DoEvents and thus the End statement, you must know exactly what you're doing. Golden rule: avoid DoEvents, End, (and variants) at all costs...

quote:
Originally posted by DragonX
And second, it doesn't the launch my browser. Maybe i just overlooked something *-)
The example of the ShellExecute API is for VB only, not for VB.NET. In VB.NET the syntax to declare API's is much different.

quote:
Originally posted by DragonX
Edit: Woohoo, i got it wo work :) by bypassing the API too ;) Here's how i did it
code:
System.Diagnostics.Process.Start(URLString)


As you noticed, there are many major differences in VB and VB.NET. VB doesn't know a method to 'execute' an URL, VB.NET does apparently (so indeed, no need for the API there)... (PS: this is indeed the benefit of looking things up by yourself, in the end you'll learn a lot more that way (y)(y))

PS: but the general tips I gave in my previous post (and in this post about variants vs. strings and about the End statemant) are also valid for VB.NET...

This post was edited on 10-05-2005 at 04:19 PM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
10-05-2005 03:33 PM
Profile PM Find Quote Report
YottabyteWizard
Senior Member
****

Avatar

Posts: 709
Reputation: 23
37 / Male / Flag
Joined: Mar 2005
RE: VB/Web Help
OMG you guys sure know a lot of VB. I can't isntall VB.NET in this computer, maybe the prob is I've Media Center :O
10-05-2005 04:15 PM
Profile E-Mail PM Find Quote Report
segosa
Community's Choice
*****


Posts: 1407
Reputation: 92
Joined: Feb 2003
RE: VB/Web Help
Not trying to catch you out or anything CookieRevised, but you said using the 'End' statement which ends your application can cause memory leaks. I thought memory leaks are things which occurr only while your program is running?

YottabyteWIzard: Media Center is just XP afaik, so I don't think that's the reason.

This post was edited on 10-05-2005 at 07:21 PM by segosa.
The previous sentence is false. The following sentence is true.
10-05-2005 07:19 PM
Profile PM Find Quote Report
Ezra
Veteran Member
*****

Avatar
Forgiveness is between them and God

Posts: 1960
Reputation: 31
37 / Male / Flag
Joined: Mar 2003
RE: VB/Web Help
How do you use the unload statement with VB.NET? I can't find anything about it on MSDN
[Image: 1-0.png]
             
10-05-2005 07:23 PM
Profile PM Web Find Quote Report
YottabyteWizard
Senior Member
****

Avatar

Posts: 709
Reputation: 23
37 / Male / Flag
Joined: Mar 2005
RE: VB/Web Help
quote:
Originally posted by segosa
YottabyteWIzard: Media Center is just XP afaik, so I don't think that's the reason.
I know that, but it's my only theory because i reinstalled Media Center and still can't install VB.NET, and when i had XP Pro SP2 and i can. Ideas?
10-05-2005 08:08 PM
Profile E-Mail PM Find Quote Report
DragonX
Full Member
***

Avatar

Posts: 226
Reputation: 10
40 / Male / –
Joined: Aug 2005
O.P. RE: VB/Web Help
quote:
Originally posted by Ezra
ause serious errors like memory leaks, crashing, freezes and what not, if you don't know exactly what you're doing and you're using 'advanced' stuff as classes and objects...

Here ya go:
code:
Me.Close()

Funny thing is i knew that, i just dunno y i didn't use it lol

quote:
Originally posted by CookieRevised
Golden rule: avoid DoEvents
Do u mean like
code:
Do
i += 1
Loop While (i < 10)


quote:
Originally posted by YottabyteWIzard
I know that, but it's my only theory because i reinstalled Media Center and still can't install VB.NET, and when i had XP Pro SP2 and i can. Ideas?
Do you have the dvd version or the cd version ? Can u atleast launch the install ?

--------

Last thing, is there a way to catch a glodal click, like in Java ? Basically what i wanna do is if the user clicks anywhere in the form (which has only an image and labels) i want it to do a me.Hide().

Thx again for all the help, u guys are the best!! :D
[Image: dsd-mi_616175.png]
10-05-2005 09:00 PM
Profile E-Mail PM Web Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15517
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: RE: VB/Web Help
quote:
Originally posted by segosa
Not trying to catch you out or anything CookieRevised, but you said using the 'End' statement which ends your application can cause memory leaks. I thought memory leaks are things which occurr only while your program is running?
Indeed, but in some cases VB doesn't clean up everything correctly when you force quit the app, usually it results in a crash though.

quote:
Originally posted by DragonX
quote:
Originally posted by CookieRevised
Golden rule: avoid DoEvents
Do u mean like
code:
Do
i += 1
Loop While (i < 10)

No, DoEvents is a special function/stamement in VB to prospone the execution and to let other processes in the same thread perform its events. Again this is VB, dunno if this also exists in VB.NET, but I do think so (maybe under a different name though)...
.-= A 'frrrrrrrituurrr' for Wacky =-.
10-05-2005 09:48 PM
Profile PM Find Quote Report
YottabyteWizard
Senior Member
****

Avatar

Posts: 709
Reputation: 23
37 / Male / Flag
Joined: Mar 2005
RE: VB/Web Help
quote:
Originally posted by DragonX
Do you have the dvd version or the cd version ? Can u atleast launch the install ?
I had CD version, and now i have DVD version and still the same problem, i can install though the end but when finishing the installation keep poping out errors.... by the Registry part, not quite sure, i'll try to reintall again tomorrow and post on another thred my problem with screenies and keep out of this thred with another problem.
10-06-2005 04:44 AM
Profile E-Mail PM Find Quote Report
Pages: (2): « First « 1 [ 2 ] Last »
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On