Solved

manipulating text

Posted on 2006-11-21
8
133 Views
Last Modified: 2010-04-30
This is a continuation of the following post

http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_22050353.html

the code below works great but I need it is moving text that I need to stay in the same position to the right depending on the length of the amount.

For instance,

109290511122555        *****WORKORDR12.00               NO
2Amount Charged  

109290511122555        *****WORKORDR1200.00               NO
2Amount Charged  


Should be
109290511122555        *****WORKORDR12.00               NO
2Amount Charged  

109290511122555        *****WORKORDR1200.00           NO
2Amount Charged  

I need the words letters NO to remain in the same position no matter what the  size of the amount.

Can anyone help?


Option Explicit

Private Sub Command1_Click()
   Dim FF         As Integer
   Dim Length     As Long
   Dim sText      As String
   Dim vSplit()   As String
   Dim sValue     As String
   Dim pos        As Long
   Dim i          As Long
   Dim j          As Long
   
   FF = FreeFile
   Open App.Path & "/WorkOrder.txt" For Input As #FF
   Length = LOF(FF)
   sText = Input$(Length, FF)
   Close FF
   vSplit = Split(sText, vbCrLf)
   For i = 0 To UBound(vSplit)
      If Left$(vSplit(i), 1) = "2" Then
         sValue = FormatNumber$(Val(Mid$(vSplit(i), 19)), 2)
         pos = InStr(vSplit(i - 1), "WORKORDR") + 7
         If pos Then
            For j = pos To Len(vSplit(i - 1))
               If Mid$(vSplit(i - 1), j, 1) = " " Then
                  vSplit(i - 1) = Left$(vSplit(i - 1), j) & _
                     sValue & Mid$(vSplit(i - 1), j + 1)
                  Exit For
               End If
            Next
         End If
      End If
   Next
   For i = 0 To UBound(vSplit)
      Debug.Print vSplit(i)
   Next
   sText = Join(vSplit, vbCrLf)
   FF = FreeFile
   Open App.Path & "/WorkOrderNew.txt" For Output As #FF
   Print #FF, sText
   Close FF
End Sub
0
Comment
Question by:earngreen
  • 4
  • 4
8 Comments
 
LVL 10

Expert Comment

by:Clif
Comment Utility
Here's one way:

'Create a string the total length that you will write:
sWriteLine = Space$(56)

'The put the fields where you need them:
Mid$(sWriteLine, 1) = sAccountNumber '(109290511122555)
Mid$(sWriteLine, 24) = "*****WORKORDR"
Mid$(sWriteLine, 37) = sAmount 'Formatted (1200.00)
Mid$(sWriteLine, 55) = "NO"

'Write sWriteLine to the file
0
 

Author Comment

by:earngreen
Comment Utility
So are you saying rebuild the file again?
0
 
LVL 10

Expert Comment

by:Clif
Comment Utility
No, I'm saying that, instead of sText = Join(vSplit, vbCrLf), you should build a string as I suggested above.

Instead of creating vSplit, though, you should put your data in named variables.  vSplit(1) means nothing, but sAccountNumber is easier to understand what the code is trying to do.  Trust me, it will be a lot easier two or three years from now when you (or someone else) has to modify your code.
0
 

Author Comment

by:earngreen
Comment Utility
OK,

I am still working on this but here is what I have. I apologize for being a little slow but new to VB6. The following is what I came up with.
Do I just want to print out the swriteline at the end?


//Total Lenght of the file
sWriteLine = Space$(56)

'The put the fields where you need them:
sAccountNumber = Mid$(sWriteLine, 1) //sAccountNumber '(109290511122555)
sWorkOrder = Mid$(sWriteLine, 24) //"*****WORKORDR"
sAmount = Mid$(sWriteLine, 37)//sAmount 'Formatted (1200.00)
Confirmation = Mid$(sWriteLine, 55) //"NO"
Description = Mid$(sWriteLine, 57) //2AmountCharged

sAccountNumber & sWorkOrder & SAmount & Confirmation & Vbclrf &_
Description
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 10

Accepted Solution

by:
Clif earned 500 total points
Comment Utility
I'm not sure what you'll be wanting to do with the sWriteline at the end, that wasn't part of your initial question.

But, if you do print it out, in fixed-width font, all of the NO's will line up.
0
 

Author Comment

by:earngreen
Comment Utility
OK,

The approach that you describe above will work. However, It gets back to one of my original problem in the following post

http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_22050353.html

It takes the value that I want to move from line two to line one.

For Instance,

if I have

109290511122555        *****WORKORDR                          NO
2Amount Charged  12.00

109290511122555        *****WORKORDR                          NO
2Amount Charged  1200.00

And it returns this

109290511122555        *****WORKORDR                         NO
2Amount Charged  

109290511122555        *****WORKORDR12.00                 NO
2Amount Charged  


0
 
LVL 10

Expert Comment

by:Clif
Comment Utility
Work picked up a bit, so I'll have to get to this as I can.

Just to clarify, you need this:

109290511122555        *****WORKORDR                          NO
2Amount Charged  12.00

109290511122555        *****WORKORDR                          NO
2Amount Charged  1200.00

To return this:

109290511122555        *****WORKORDR1200.00                   NO
2Amount Charged

109290511122555        *****WORKORDR                          NO
2Amount Charged


Right?

0
 

Author Comment

by:earngreen
Comment Utility
Sorry,

I finally figured it out. I jsut needed to pad the value and that strightened it out.

Thanks for the assistance.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now