|
Hello ,
Is there a way in vb.net that i can declare few variables and assign a
constant value to all of the variables at the same time?
Here is how i am trying ...
Dim x, y, p, q As Integer
x = y = p = q = 10
it doesn't throw any exception but when i debug these values variables
just have 0 but not 10.
How do i do this?
Tahnks-L
|
|
|
|
|
You can't really set them all with one line of code.
Dim x, y, p, q As Integer
x = 10
y = 10
p = 10
q = 10
"People who never make mistakes, never do anything."
My Blog
|
|
|
|
|
Yes thats what i thought that we can't assign all of them at once with the same value.
I was just curious was there a way to do it. How ever thanks for your time
Thanks
-L
|
|
|
|
|
No there is no way you could do so...
In fact the statement is interpreted as a = ( b = (c = 10 ) ) which is a set of boolean expressions: since c<>10 b would become 0 etc.
|
|
|
|
|
Hello ,
I am trying to manipulate the string
Dim str as string = "YS3EB45E833005745_20050610_WINDSHIELD"
Now i just need the part that is in between the two underscores. That is in the above string i just need that part 20050610.
I am trying to remember the function that i had used to identify the occurances of a particular character in the past.
Can any one help me with this?
Thanks
-L
|
|
|
|
|
you can use string.split() and it will be the second item in the returned array.
do you need to investigate an online backup[^] company
|
|
|
|
|
Could you please elobarate on how do we implement this in my case?
Thanks
-L
|
|
|
|
|
|
Yes this works here is what i did off course the same
Dim MyString As String = "YS3EB45E833005745_20050610_WINDSHIELD"
MySplitLine = MyString.Split("_")
MessageBox.Show(MySplitLine(1))
and its returning 20050610
But like you mentioned .ToCharArray()may be an efficient way of doing it.
we need to use ToCharArray() because we are splitting a string?
Thanks
-L
|
|
|
|
|
Slow Learner wrote: we need to use ToCharArray() because we are splitting a string?
No, I use it for documentation purposes, it is more clear what the code is doing, imo, when I see tochararray(). That being said, I recall I may have had issues when I had a string longer than one charater. Nonetheless, your code returns the correct results, so at the end of the day, our code is managerially equvilant
Slow Learner wrote: .ToCharArray()may be an efficient way of doing it.
Although many people will argue this point to death, I feel efficent is only releveant in the 20% of the code that does 80% of the work in the program. Most of a program is scaffolding to support the core logic, anyway. Therefore, who cares if some ui element take 20 extra ns to complete. The user cant tell the difference! 80% of the code should be simple and readable 20% (that which does the work) should be "efficent"
do you need to investigate an online backup[^] company
|
|
|
|
|
Sure i like your arugment. If the code is more readable and understandable it would be easy for another developer who comes in after we left. I agree with you
thanks
-L
|
|
|
|
|
If you would like the code to be more efficient, you should get rid of the Split all together (as that creates at least two strings that you don't even use). Use IndexOf to locate the first and second "_" in the string, then use Substring to get the part of the string in between.
Still I agree with Jason's opinion that most of the code doesn't need to be optimized to the max. Consider how often the code will be used, and how much resources it uses compared to the surronding code.
Simple code that works is always better than optimized code that doesn't.
---
b { font-weight: normal; }
|
|
|
|
|
Good explanation and thanks for the reply. I am excited trying the same thing in different ways and figure out the best option.
Here is how i am trying to get the index of the string i posted in my string YS3EB45E833005745_20050610_WINDSHIELD
Dim indexOf_ As Integer
indexOf_ = fileName.IndexOf("_")
the above one gives me the index of the first occurance of the "_". How do i get the second occurance of the "_" and then use the substring?
Thanks for the reply,
-L
|
|
|
|
|
You can use either LastIndexOf("_") or IndexOf("_", indexOf_ + 1).
For Substring you need the index of the first character and the length.
The first character is located at indexOf_ + 1.
The length I believe is the index of the second _ minus indexOf_ minus one.
---
b { font-weight: normal; }
|
|
|
|
|
I want to connect sql with vb.net and want to add and delete the record programically i.e using insert alter command etc. If somebody helps me , I am in urgent need of it.
Thanks and Regards
Pankaj Garg
|
|
|
|
|
|
|
I think you want to show something on form2 based on a value passed from form1, if thats rigth, just add the following code to form2
'Val can be any name and any type
Public Overloads Sub show(ByVal val As Integer)
'Load your custItemsDataSet or assign Val to a local variable or do what you got to do to load your dataset
Me.Show()
End Sub
Alexei AR
Theres always a better way
Look for it
|
|
|
|
|
I am doing code on treeview , where I got stuck in attaching files an folder icon to the particular file and folder dynamically.I mean I want to attach the file and folder icon dynamically during populating the treeview with system drives.If somebody send me the code for the same .I am in urgent need of it.
Thanks and Regards
Pankaj Garg
|
|
|
|
|
How do you create and populate DBASE3 files using Data Access Objects (DAO) from Visual Basic 6?
TJWH
|
|
|
|
|
Use ODBC Driver for Dbase3
DR
|
|
|
|
|
I know it's a bit cheeky but have you got a code snippet to give me a head start?
TJWH
|
|
|
|
|
no i dont have code as i dont use ODBC . look in google
Divya Rathi
|
|
|
|
|
can anyone help me to add RichTextBox to DataGridView abd Show RTF Formmatted Code in DataGridView?
DataGridView does'nt show rtf in the Text columns and i want to add Richtextbox to datagrid view to show them.
|
|
|
|
|
Background: I have a number of PC's (XP) that i have on remote sites and i want to write a piece of software that will back them up to my server to save me the time from going to do it manually every week!
What I want: Guidance on what i should be doing! I am a relativly new developer in vb.net(2003) and would like some pointers in the right direction.
Cheers
Denis
|
|
|
|