Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

manipulating text

Posted on 2006-11-21
8
Medium Priority
?
144 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
ID: 17988895
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
ID: 17989423
So are you saying rebuild the file again?
0
 
LVL 10

Expert Comment

by:Clif
ID: 17995080
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:earngreen
ID: 18112805
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
 
LVL 10

Accepted Solution

by:
Clif earned 2000 total points
ID: 18114412
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
ID: 18122625
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
ID: 18123236
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
ID: 18123337
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses

963 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