Solved

manipulating text

Posted on 2006-11-21
8
137 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

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 500 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

751 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