Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

string manipulation

Status
Not open for further replies.

met

IS-IT--Management
Jul 1, 2000
13
0
0
US
As network admin I don't get into programming much but I have a project at work where I have to read in a text file formated as:10000000006194700<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10011234564371720<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10021234562200930<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10031234568499910<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10041234566727890<br>and so on until....EOF<br>then write out to another file formated as:<br>&nbsp;1001,123456,,,<br>&nbsp;1002,123456,,,<br>&nbsp;1003,123456,,,<br>&nbsp;1004,123456,,,<br>The first 4 dig. of input file are machine id's the next six are readings, remainder not used. On the output side the commas are placeholders(delimited).Am using vb6. Need help!!! thanks.......&nbsp;&nbsp;<br>
 
To insert a comma after the fourth position, assuming:<br>A$ = &quot;10011234564371720&quot;<br>A$ = Left$(A$, 4) + &quot;,&quot; + Right$(A$, Len(A$) - 4)<br><br>Then A$ will equal &quot;1001,1234564371720&quot;. That is the value you will write to the new file.<br><br>It would be better to post this question in the Microsoft VB 5&6 forum. There are experts there who probably know an easier way to do this. <p> <br><a href=mailto: > </a><br><a href= plain black box</a><br>
 
Dont know if earlier syntax holds but with GWBASIC I would use<br>B$=left$(A$,4):C$=mid$(A$,5,6) then write it out<br>Print #x B$;&quot;,&quot;;C$;&quot;,,,&quot;&nbsp;&nbsp;&nbsp;&nbsp;assuming that you want terminator after the last comma <p>Ed Fair<br><a href=mailto: efair@atlnet.com> efair@atlnet.com</a><br><a href= > </a><br>Any advice I give is my best judgement based on my interpretation of the facts you supply. <br>
Help increase my knowledge by providing some feedback, good or bad, on any advice I have given.<br>
 
Here is what I wound up with that works,i.e., it gives me the desired output of: 1234,123456,,, written to a text file.<br><br>Private Sub cmdConvert_Click()<br>Dim Inputfile As String<br>Dim OutPutfile As String<br>Dim F1 As Integer<br>Dim F2 As Integer<br>Dim i As Variant<br>Dim j As Variant<br>Dim temp As Variant<br>Dim temp1 As Variant<br>Dim ctr As Integer<br>ctr = 0<br>F1 = FreeFile<br>F2 = F1 + 1<br>Inputfile = txtInput.Text<br>OutPutfile = txtOutput.Text<br>ReDim conv(2, 0)'declared in general<br>Open Inputfile For Input As #F1<br>Open OutPutfile For Output As #F2<br>Do While Not EOF(F1)<br>&nbsp;&nbsp;&nbsp;Line Input #F1, Inputfile<br>&nbsp;&nbsp;&nbsp;ReDim Preserve conv(2, UBound(conv, 2) + 1)<br>&nbsp;&nbsp;&nbsp;conv(0, UBound(conv, 2)) = Left$(Inputfile, 4)<br>&nbsp;&nbsp;&nbsp;conv(1, UBound(conv, 2)) = Mid(Inputfile, 5, 6)<br>&nbsp;&nbsp;&nbsp;<br>Loop<br>'--------- print loop-----------<br><br>For j = 1 To UBound(conv, 2)<br>temp = conv(0, j)<br>temp1 = conv(1, j)<br>Debug.Print temp & &quot;,&quot; & temp1 & &quot;,&quot; & &quot;,&quot; & &quot;,&quot;<br>ctr = ctr + 1<br>Next j<br>txtNumFiles.Text = ctr<br>Close #F1<br>&nbsp;Close #F2<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>End Sub<br><br><br>Private Sub cmdExit_Click()<br>Unload Me<br>End<br>End Sub
 
Am curious about two items in your program. You used line input. In GW you would just input it as a variable.&nbsp;&nbsp;Two lines later you used mid(, suspect that was a typo.<br>Seems that GW was much easier to do this with. Once again MS has improved things.<br>I still use the GW or IBM that goes back to DOS4.x.&nbsp;&nbsp;I do have the compiler 2.0 I think it is , but have only used it for test purposes. And haven't used the Q that came with DOS 5.0 except in limited trials or for grandkids to play games.<br>And as far as data conversion is concerned I have used the technique to break apart up to 500mb unix based data files of record lengths of up to 400 bytes. No difference except had to do it one byte at a time and build the variables byte by byte and record end on LF only. <p>Ed Fair<br><a href=mailto: efair@atlnet.com> efair@atlnet.com</a><br><a href= > </a><br>Any advice I give is my best judgement based on my interpretation of the facts you supply. <br>
Help increase my knowledge by providing some feedback, good or bad, on any advice I have given.<br>
 
Ed, Line Input #n is useful for reading a line of text (up to the CR-LF) into a variable, ignoring any comma delimiters.<br><br>Mid(Inputfile, 5, 6) or Mid$(Inputfile, 5, 6) are both acceptable ways of retrieving 6 bytes from the &quot;Inputfile&quot; string starting with the 5th byte.<br><br>This looks like it was written in Visual Basic. If you are still using GWBASIC you might consider an upgrade.<br><br>Oops! There I go again. <i>&quot;Mine is not to question why...&quot;</i><br><br> <p> <br><a href=mailto: > </a><br><a href= plain black box</a><br>
 
The only extranous code is the declaration of i which was left over from a previous print loop attempt. Line input reads one line at a time- I probably could have gotten away with input. The mid$(Inputfile,5,6)gives me the six characters in the string starting from the the fifth position
 
Sorry, met. It looks like we posted simultaneously. I wouldn't have responded if I had seen your explanation. <p> <br><a href=mailto: > </a><br><a href= plain black box</a><br>
 
No problem your explanation was maybe a little more detailed. I should note also that this version of the program printed to the debug window and not to the file. And your right it was written in VB6.
 
Is it working well? No problems? That's all that matters.<br><br>Good luck and post back if you run into any more problems. As I mentioned earlier, the VB 5&6 forums are populated with many more users than this one. Your chances of getting a good answer are much better. The &quot;Microsoft BASIC&quot; forum seems to be here to allow discussion regarding mixed version support (let's say my VB6 app has to rely on an app created in Quick Basic).<br><br>Once again, good luck.<br> <p> <br><a href=mailto: > </a><br><a href= plain black box</a><br>
 
Yes it works great, as a matter of fact I wrote code based upon this module to convert this format back into a telzon reader.
 
The question on line input was because the original data had no commas, therefore it could be read in as a variable.<br>the question on mid$ was due to the syntax for GW.<br>Both questions were answered to my satisfaction and we continue my education. At least I wasn't totally out in the woods.<br>Probably too late to consider a change to VB. Have considered the purchase, but I'm not supporting much basic stuff any more. In fact the only VB I've looked at in the last year was the &quot;Love Bug&quot; script. And if I changed , then I would have to modify a whole bunch of stuff I use.<br>Thanks <p>Ed Fair<br><a href=mailto: efair@atlnet.com> efair@atlnet.com</a><br><a href= > </a><br>Any advice I give is my best judgement based on my interpretation of the facts you supply. <br>
Help increase my knowledge by providing some feedback, good or bad, on any advice I have given.<br>
 
hey met<br><br>I noticed that you could have saved a teeny weeny bit of typing if you change one line in your <i>print loop</i> code<br><br><font color=red>Debug.Print temp & &quot;,&quot; & temp1 & &quot;,&quot; & &quot;,&quot; & &quot;,&quot;</font><br><br>to <br><br><font color=red><b>Debug.Print temp & &quot;,&quot; & temp1 & &quot;,,,&quot;</font></b><br><br>Not that it matters, since the programs in working fine. I just wanted to add my two cents worth.<br><br>And you're right about it printing to DEGUB window.&nbsp;&nbsp;If you wanted it to print to another module (I mean Form) and the output file, make sure that you have something like<br><br><b>Print #F2, temp & &quot;,&quot; & temp1 & &quot;,,,&quot;<br><i>Form(0)</i>.Caption = temp & &quot;,&quot; & temp1 & &quot;,,,&quot;</b><br><br>Please note that this will change the Caption in the MAIN form only.&nbsp;&nbsp;So, if you don't want that then make sure that that you change <font color=red>Form(0)</font> to your current form's name (ex: &quot;frmProcessing.Caption = .....&quot;)&nbsp;&nbsp;or&nbsp;&nbsp;current form's index number (if you know it).<br><br>Again, just adding my two cents worth. <p> <br><a href=mailto: > </a><br><a href= > </a><br>Secrete of life: If Husband = Happy then Wife = Unhappy. If Wife = Happy then Husband = Unhappy. If Parents = Happy then Kids = Unhappy. If Kids = Happy then Parents = Unhappy.
 
MiggyD, good observations. I note that you like MDI forms.<br><br>Ed, don't worry about making global conversions after an upgrade. I have seven versions of BASIC installed on this computer: GWBASIC, Qbasic, QB45, Basic 7, VB2, VB3 and VB6. And I use <i>all</i> of them (well, I don't use 7 and VB3 much anymore and I only use GW to convert some ancient BAS files to a format readable by the others).<br><br>Why so many? Every time Microsoft finds a &quot;better&quot; way it adds a few features and removes a few features. I really don't understand the reasoning behind this but it seems to part of Microsoft's master plan for global domination.<br><br>My main work horses are QB 4.5 and VB 6.0. I have found, if you can't do something using one or both, it <i>just can't be done</i>. In my view, a well-rounded BASIC programmer should keep installations of GWBASIC (for the legacy items), Qbasic (as shipped prior to Win9x), Visual Basic 2 (to develop 16 bit applications), Visual Basic Latest Version (to develop 32 bit apps) and Quick Basic 4.5 (to perform the tasks that can't be performed using any of the others). The hypothetically well-rounded BASIC programmer might consider maintaining installations of MASM and/or Turbo Assembler to build hyper-fast functions for BASIC libraries.<br><br>MiggyD, I think this thread pretty much answers Mike Lacey's question about deleting the forum and redirecting the users to the VB forum. Aren't you glad that didn't happen?<br> <p> <br><a href=mailto: > </a><br><a href= plain black box</a><br>
 
After review of entire thread, I'm beginning to like the GW better and better. I understand the need to add features but the cost was about 20 extra lines of code in the example. I may not follow good programming practices in doing these little projects but it seems to me that GW was the solution crying out for this problem, if only met had it available.<br>Probably feel this way because of my path in getting to where I am. Like the KISS principal.<br> <p>Ed Fair<br><a href=mailto: efair@atlnet.com> efair@atlnet.com</a><br><a href= > </a><br>Any advice I give is my best judgement based on my interpretation of the facts you supply. <br>
Help increase my knowledge by providing some feedback, good or bad, on any advice I have given.<br>
 
MiggyD,<br>Thanks for the input but when I received notice of these posts I had already written and deployed the program. The only reference I had to it was the test version on my personal computer at home, so to answer edfair's question I pasted what I had. The only visual output I needed was the total number of files converted which was handled by the textbox reference &quot;txtNumFiles.Text = ctr&quot;, but the saving code issue (Debug.Print temp & &quot;,&quot; & temp1 & &quot;,,,&quot;)<br><br>was one of those things that never occured to me-thanks for future reference. And Alt255 I agree; I'm gald they didn't eliminate this forum-I think it's great--as are you guys. Thanks <br>Mike(MET) <br>
 
<b>Alt255</b> -- <br>1.&nbsp;&nbsp;&nbsp;&nbsp;As you know, it's a lot easier to manipulate MDI forms to your liking.<br><br>2.&nbsp;&nbsp;&nbsp;&nbsp;Since there's one being displayed (not knowing if it is working or if the system is hung), why not use it to your advantage?&nbsp;&nbsp;Remember the statment <i>&quot;As network admin I don't get into programming much...&quot;</i> made me think that it's not his/her forté--so why re-invent the wheel?&nbsp;&nbsp;Just kill two birds with one stone.<br><br>3.&nbsp;&nbsp;&nbsp;&nbsp;This is a perfect example of why not to close this forum.&nbsp;&nbsp;There is a multitude of people with varied responses and all are valid.&nbsp;&nbsp;(As I keep saying: <i>&quot;I know a lot about something, and a little about everything.&quot;</i> and this holds true about <font color=red><b>EVERYONE</b></font>).<br><br><b>met</b> --<br>Like I said before, just adding my two cents in.&nbsp;&nbsp;The main thing is that the program is working as required, aesthetics is not a requirement and I'm possitive that the end user(s) will not care on whether it has an extra 7 bytes of code or not. They'll only care if it doesn't work.<br><br>So that's it in a nut shell, I still can't believe Alt255 has a copy of GW-basic laying around--but his response makes sense.&nbsp;&nbsp;I say to him <b>BRAVO!!</b>. &lt;clapping&gt; <p> <br><a href=mailto: > </a><br><a href= > </a><br>Secrete of life: If Husband = Happy then Wife = Unhappy. If Wife = Happy then Husband = Unhappy. If Parents = Happy then Kids = Unhappy. If Kids = Happy then Parents = Unhappy.
 
I'm clapping too but I'm clapping for edfair. My comment about upgrading wasn't fair or necessarily practical. The discussion about GWBASIC made me remember that about five years ago I saw GW in use in a business environment (a chemical testing lab). A tech was using GWBASIC on an 80286 to knock out some intermediate calculations.<br><br>I guess the point is that it doesn't have to be high-tech or visually appealing to do the job. Don't try to fix or replace something that works and is perfectly suited to the task. <p> <br><a href=mailto: > </a><br><a href= plain black box</a><br>
 
Well put <p> <br><a href=mailto: > </a><br><a href= > </a><br>Secrete of life: If Husband = Happy then Wife = Unhappy. If Wife = Happy then Husband = Unhappy. If Parents = Happy then Kids = Unhappy. If Kids = Happy then Parents = Unhappy.
 
Thanks.&nbsp;&nbsp;All my hats will be too small for a while.&nbsp;&nbsp;<br>Came to this point from supporting a customer in basic running on a 6800 based machine under the Flex operating system before IBM had hard disk capability. Upgrade was to a 386 running Desqview and 9 windows with 9 different GW jobs concurrently in a billing and inventory application. Customer stayed with the 6800/6809 series for about 8 years, then 7 years with 386, then to Unix and 12 users for 3 years until they went remote Unix networking. Basic on one machine or another up till the Unix multiuser.<br>And the funny part, the owner of the company didn't like the upgrade to the 386. It was too hard to use.<br> <p>Ed Fair<br><a href=mailto: efair@atlnet.com> efair@atlnet.com</a><br><a href= > </a><br>Any advice I give is my best judgement based on my interpretation of the facts you supply. <br>
Help increase my knowledge by providing some feedback, good or bad, on any advice I have given.<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top