|
Hi,
I'm not going to give you any solution; I do suggest you try and solve this little task in several steps, it is a typical beginner's mistake to try and solve it in one complex statement (which often never gets composed correctly). With many statements, you can execute the required steps, similar to your explanation in English words, AND you can check intermediate results.
So don't worry if you use ten lines of code for this; once you got it working correctly, you can try and optimize it.
One hint: you don't need loops, a few simple string methods will do.
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
You will could use the following methods of your string variable, to achieve your requirements :-
.Length
.Substring
.Replace
like so:-
Dim FullString = "string of 23 characters"
Dim FirstPart As String
Dim SecondPart As String
FirstPart = FullString
SecondPart = FullString.Substring(FullString.Length /2)
FirstPart = Replace(FirstPart, SecondPart, "")
Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|
|
I think is this the code you need:
Dim FullString As String = "String of 23 characters"
Dim HalfStringLen As Integer = Fix(FullString.Length / 2)
Dim FirstPart As String = FullString
Dim SecondPart As String = ""
Do
If FullString(HalfStringLen) = " " Then
FirstPart = Microsoft.VisualBasic.Left(FullString, HalfStringLen)
SecondPart = LTrim(Microsoft.VisualBasic.Right(FullString, FullString.Length - HalfStringLen))
Exit Do
End If
HalfStringLen = HalfStringLen + 1
Loop Until HalfStringLen = FullString.Length At end of loop, FirstPart and SecondPart will contain FullString spitted.
Note that If the full string have not espaces, FirstPart will contain the entire FullString.
Ignazio
|
|
|
|
|
Hi Ignazio and Steve,
Thanks for your replies, they have both helped me a lot and it's helped me to solve my problem.
again, thanks
Steve
Thanks for your help and advice!
Steve
|
|
|
|
|
Congratulations! You managed to con someone into doing your work for you! Don't do it again.
|
|
|
|
|
I have a very strange request from client.
The scenario is: I have a server with some media file assigned to unique id's and the server is conected to a series of USB flash drives port (20). Now, a user comes down & plugin his/her USB drive. Every USB drive has an .txt file, the .txt file names are nothing but the unique id's which are already stored on server.
Once the user plugin he's/her USB drive, the server should be able to read the .txt file name(unique id) and get all the media files from the server and copy it to USB flash drive. Once its done we shouls close the port.
Just to let you guys know, no monitor will be there and once we copy the files to USB it should intimate the User.
I know it sounds strange. Any help / direction would be truly appreciated.
Thanks
Sagar
|
|
|
|
|
The hard part, I guess, is detecting the drive being attached. I'm not sure there's an event you can use, although autoplay does fire in the OS itself. You might just check what drives are connected every few seconds, and if you find a new one, go ahead and read the text file. It sounds straightforward from there, look up the files from the Ids and copy them. I'd expect a windows service to do this work.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Hi,
nothing strange about that. Here are some pointers:
1.
inserting/removing a device generates a Windows message, which you can capture by overriding WndProc in your Form; here is a skeleton method for that (sorry it is C# code, VB.NET code can do similar things):
WM_DEVICECHANGE = 0x0219,
DBT_DEVICEARRIVAL= 0x8000,
DBT_DEVICEREMOVECOMPLETE= 0x8004,
protected override void WndProc(ref Message m) {
if (m.Msg==WM_DEVICECHANGE) {
int wParam=(int)m.WParam;
int lParam=(int)m.LParam;
log("WM_DEVICECHANGE wParam="+wParam.ToString("X8")+" lParam="+lParam.ToString("X8"));
if (wParam==DBT_DEVICEARRIVAL) DeviceAdded();
else if (wParam==DBT_DEVICEREMOVECOMPLETE) DeviceRemoved();
}
}
DeviceAdded() would be your method where most of the action is.
2.
rather than having text files to identify the users, I would use the unique ID that seems to be present in most if not all USB memory sticks; it can be obtained using WMI. Advantage is it is much more tamper proof, users could easily change their text file (unless you somehow encrypted it).
3.
warning: depending on USB stick manufacturer, Windows version, and/or system settings, the stick may or may not be cached; when it is, you need to use "Safely remove hardware" otherwise the next time the stick gets inserted in some system, a dialog "Should I scan and fix..." would appear.
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
modified on Thursday, September 17, 2009 9:25 PM
|
|
|
|
|
Hey, Thank you for your response.
Felt good after reading "nothing strange" .
Reason for using a .txt file: the file name would be nothing but a unique Id. Bsacially I need to get that id and send it across to server, based on that id I need to pull few media assets which belogs id and need to copy it on USB drive.
Once we done with copying the files, we have to intimate the users.
Please note: no monitors will be there.
User could just see few USB ports to plugin the flash drive.
Any direction / helpo would be trul appreciated.
Thanks,
Sagar
|
|
|
|
|
Sagar Mishra wrote: Once we done with copying the files, we have to intimate the users.
Sagar Mishra wrote: no monitors will be there.
I see two ways:
1.
put a sticker "when your USB stick stops flashing, files got loaded; now wait 5 seconds and remove it."
(this is assuming your USB stick has a busy LED, I haven't seen any without LED yet).
2.
put a red LED on top of each USB receptacle; connect it to the PC, and switch it on when you detected the device presence, and off again when done copying plus 5 second wait.
This[^] may help if your system has a parallel port; a few LEDs can also be controlled through the control lines of a serial port.
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Sagar Mishra wrote: Just to let you guys know, no monitor will be there and once we copy the files to USB it should intimate the User.
Marty's loud speakers works very well
Seriously probably a light/LED light connected to PCI slot should work, or through speaker.
Your next problem probably is how to tell the user an error has occurred, some files are not found on server, or the USB is full.
|
|
|
|
|
Yeah, do NOT email people to get a problem solved. I didn't answer because Luc's answers were already there and the best answer you're going to get.
In my humble opinion, basing things on the existance and filename of a text file on the stick is a bad idea. It's just too easy to accidentally delete/move/rename the text file.
|
|
|
|
|
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Hi,
I am very new to coding, and have purchased training videos on VB6, but I've not completed them as yet. I live in the United Arab Emirates, and everything runs under one proxy . This being a muslim country, they block all sorts of content, including some sites that have tools that I need. I have some sample code to create an internet browser, and was wondering if I could code into it to hide my IP while browsing? Any help would be appreciated, and I look forward to becoming a pro and helping n00bs like myself on this site.
Jannie the n00b.
|
|
|
|
|
raggabox wrote: have purchased training videos on VB6
You just wasted your money. VB6 has long since been dead. VB.NET 2008 Express Edition is free and can be found here[^].
raggabox wrote: wondering if I could code into it to hide my IP while browsing?
There is no such thing. If you could hide the IP, how then would the server figure out where to send the page your downloading?
There is no way to completely prevent someone from finding you. And nothing you can do to make it harder to find you by writing code into your browser.
|
|
|
|
|
Oh I know, I have Vstudio 2008 installed and trying to watch the vids and use VB8 to code. Not easy, but getting there.
|
|
|
|
|
Soooooo, you're trying to use VB.NET 2008 code in VB6?? Yeah, good luck with that. You're going to need it.
|
|
|
|
|
No I think you misunderstood. I am watching the VB 6 videos, but I have 2008 installed. So i am trying the code they show me in vb6 on the vb8 installation. Very different I know. Most of it does work though(vb6 theory in VB8)
|
|
|
|
|
VB6 and VB.net are 2 very different things.
Your better off learning VB.net... Watching a VB6 video and trying to code in VB.net will only confuse you.
|
|
|
|
|
Thanks for the reply. Guess its back to the drawing baord
|
|
|
|
|
No, not really. The point is if you're using the VB6 IDE, compiler, and/or technqiues, you're really wasting your time. VB6 is not an OOP-compliant language. You're really teaching yourself a lot of bad habits by using it and making your job harder learning the true OOP techniques of VB.NET.
|
|
|
|
|
I am currently creating a plugin for Visual Studio .NET. This plugin is to help database entry. When the plugin is running I want to be able to select a file, right click it, and have a menu of options to be able to do with this particular file. Any suggestions on helping how to do this? I am using the MVP model for coding.
|
|
|
|
|
hello all,
Finally I could able to save my dynamic array data into text file. But it is not formated it is saving as a big line. I want to format my data into
9 X 9. Can anyone help me please.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveButton.Click
Dim cellValue As String, i As Integer
Dim returnValue As Boolean
Dim FileWriter As StreamWriter
Dim results As DialogResult
results = SaveFileDialog1.ShowDialog
If results = DialogResult.OK Then
FileWriter = New StreamWriter(SaveFileDialog1.FileName, False)
For r As Integer = 1 To 3
For rr As Integer = 1 To 3
For c As Integer = 1 To 3
For rc As Integer = 1 To 3
cellValue = xx(r, c).rec(rr, rc).Text
returnValue = String.IsNullOrEmpty(cellValue)
If returnValue = True Then
FileWriter.Write("00 ")
Else
FileWriter.WriteLine(cellValue + " ")
End If
Next
i += 1
Next
Next
Next
FileWriter.Close()
End If
Me.Close()
End Sub
I am getting my output like this
8
00 00 00 00 00 00 00 00 00 7
00 13
00 17
00 21
00 00 00 1
00 53
00 51
00 00 00 3
00 00 00 00 00 27
00 00 00 79
00 00 00 49
00 00 00 75
00 00 00 00 00 31
00 00 00 73
00 45
00 47
00 00 00 67
00 63
00 41
00 35
00 00 00 00 00 00 00 00 00 00
but I want to format like
00 00 00 00 00 00 00 00 00
00 07 00 13 00 17 00 21 00
00 00 01 00 53 00 51 00 00
00 03 00 00 00 00 00 27 00
00 00 79 00 00 00 49 00 00
00 75 00 00 00 00 00 31 00
00 00 73 00 45 00 47 00 00
00 67 00 63 00 41 00 35 00
00 00 00 00 00 00 00 00 00
modified on Thursday, September 17, 2009 9:33 AM
|
|
|
|
|
so choose carefully between Write() and WriteLine().
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
If I wrote both write() I am getting a big horizontal line
It I choose writeline() I am getting a vertical line
I don't know how to write a break line for output format
|
|
|
|
|