|
You could use the String.Split command, but thats only if you know for sure that the desired String in the returned array is the 2nd last element.
Dim path as String = "C:\Targets\TestAirplane\TestAirplane_WebDoc\TestAirplane_HDS\01 Fuse"<br />
<br />
Dim s as String()<br />
<br />
s = path.Split(chr(92))<br />
<br />
return s(s.Length-2)
OR
if you place in a FileInfo object you can call the FileInfo.Directory.Parent method which will return the local directory of where the file is located.
Dim f as new FileInfo("C:\Targets\TestAirplane\TestAirplane_WebDoc\TestAirplane_HDS\01 Fuse")<br />
<br />
'should return TestAirplane_HDS<br />
return f.Directory.Parent.ToString
|
|
|
|
|
Anonymous wrote:
s = path.Split(chr(92))
That works good but I don't understand what (chr(92)) is doing. Specifically, what is the 92 for?
Thanks
Brad
|
|
|
|
|
Brad Fackrell wrote:
what is the 92 for?
Thats the ASCII key code for \
For more info at those key codes, you can check ASCII Character Codes[^].
BTW, if you want to be really fancy, you can use the IO.Path.DirectorySeparatorChar instead...
Hope this could help you!
|
|
|
|
|
Absofukinlutely wrote:
Thats the ASCII key code for \
Ahhh...I see. Thank you very much.
|
|
|
|
|
I'd suggest that chr(92) is a complete hack. I certainly wouldn't use it.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
How would you tackle this one?
|
|
|
|
|
Anonymous wrote:
How would you tackle this one?
How would one tackle what
|
|
|
|
|
With the \ in quotes. \ is used to escape things, so you probably need to do Split('\\') instead of Split('\').
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Oh ok, is that also in VB? I thought that escaping with \ was only in C, C++ and C#.
I never had any problems with it...
|
|
|
|
|
I dunno, but I can't imagine why else someone would use chr(92) or whatever it was.
How do you put a control character in a string in VB then ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Well, i think that is the only flaw in VB
Instead of "Blablabla\nSome more bla", you have to do "Blablabla" & vbNewLine & "Some more bla"
Also, \t = vbTab, \" = "" and \x92 = Chr(92)
A lot more typing...
Cheers!
|
|
|
|
|
Absofukinlutely wrote:
Well, i think that is the only flaw in VB
ROTFL - don't get me started.....
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
That's where the wink is for, right?
See ya!
|
|
|
|
|
i cant remember if \ is a control character in VB but certaintly in VB6 i used to use the chr(92) format quite a lot. For one project i needed to build a VBScript string containing SQL and i found using the character ref was pretty much the only way when creating a string with ' " combinations. Dont think its as much of a problem in VB.Net but i havent really tried.
jon
|
|
|
|
|
Split is probably the easiest way to do this, as has been said, but a regular expression could also be used if you wanted to.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Not sure exactly what you are after; here are several possibilities:
Where s = "C:\Targets\TestAirplane\TestAirplane_WebDoc\TestAirplane_HDS\01 Fuse"
s.Substring(0, s.IndexOf("Targets\") + 8)
Returns "C:\Targets\"
s.Substring(s.IndexOf("Targets\") + 8, s.Length - s.IndexOf("Targets\") - 8)
Returns "TestAirplane\TestAirplane_WebDoc\TestAirplane_HDS\01 Fuse"
s.Substring(s.IndexOf("Targets\") + 8, s.IndexOf("\"c, s.IndexOf("Targets\") + 8) - s.IndexOf("Targets\") - 8)
Returns "TestAirplane"
|
|
|
|
|
Is there a way to get the selectedvalue (or selectedtext or selecteditem) from a databound combobox into a string variable? I keep getting cast from datarowview to type string not valid.
|
|
|
|
|
Give one of these a try:
ComboBox.SelectedValue.ToString
OR
ComboBox.SelectedItem.ToString
|
|
|
|
|
I had already tried that.
still cast from datarowview to type string not valid
|
|
|
|
|
|
Also, have you tried:
ComboBox.Text
|
|
|
|
|
The error is in result of a query
'field_names is a string
'field_number is the underlying value
commandtext = "Select field_number,field_names From field_info where field_number = " & cbfieldEdit6.SelectedValue.ToString
cbfieldedit6.text works, but I need the underlying value
I think I will have to do it in a round about way...
commandtext = "Select field_number,field_names From field_info where field_names = " & cbfieldEdit6.text
and then use a datareader to get the value I need.
field1 = dr.getvalue(0)
oops... modified query
commandtext = "Select field_number,field_names From field_info where field_names = '" & cbfieldEdit6.text & "'"
|
|
|
|
|
|
I ended up querying the database for the underlying value using the combobox.text for the Where clause (Thankfully it doesn't cause much overhead)
I looked all over, and I am beginning to think that what I was trying to do is impossible by .net design. It is expected that you will be updating the datasource using the (updated) dataset.
.text is the only data that I could get out of a databound combobox.
|
|
|
|
|
Good Day,
I have decided that it is necessary to resize a form (new base size) as well as all of the controls it contains. But although I resize the form and its elements, when I run the program in debug mode (even after building & rebuilding both the project and solution) the changes do not take effect at run-time...only at design time.
Any help is greatly appreciated.
mtognetti
|
|
|
|