Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Is there a way that I can use the same variable more than once in a private sub?? Is there a delete variable command so this can be done???

 

e.g.

 

dim simon as string = "hello"
msgbox(simon)
simon.delete()
dim simon as string = "bye"
msgbox(simon)

 

Thanks

 

Simon

  • *Experts*
Posted

You can re-use variables as often as you wish by just re-setting its value.

Dim simon As String = "hello"
MessageBox.Show(simon)
simon = "bye"
MessageBox.Show(simon)
simon = "aloha"
MessageBox.Show(simon)

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

Posted

Sorry should have explained myself a bit clearer. I am actually using a bit of third party software and I can't seem to get it to work unless I keep on declaring a new class to a variable, therefore I am unable to performing a do loop (to tidy my code up instead of loads of repeated code) as the variable name is already declared.

 

Which is why I was hoping there is a way to delete a variable and then re-use it again???

 

Thanks in advance

 

Simon

Posted

This might be from left field, but here goes!

 

Instead of deleting couldn't you use REDIM?

 

dim simon as string = "hello"
msgbox(simon)
redim simon as integar = "15"
msgbox(simon)

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

-- Rick Cook, The Wizardry Compiled

Posted
I was wondering how you got one hundred plus posts and didn't know something like what DiverDan posted. I understand now what you meant, an example of code would be extreamly useful to help you with us answer your question.

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

  • *Experts*
Posted

@lidds:

If your variable is an object that is declared as "new", you can simply create another object, as in:

Dim o As ThirdPartyObject
Dim i As Integer
For i = 0 To 10
   o = New ThirdPartyObject()
   ' Use new instance of o here
Next

 

or in C#

ThirdPartyObject o;
for(int i = 0; i<=10; i++)
{
   o = new ThirdPartyObject();
   // Use new instance of o here
}

 

-ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

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...