Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8697023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:24:53+00:00 2026-06-13T01:24:53+00:00

Actually I am writing a file converter tool. The data values represent a 120×120

  • 0

Actually I am writing a file converter tool. The data values represent a 120×120 matrix. My first thought was two nested for loops and just a new line inside the first: Easy.

The input file has a vbNewLine each fith value.
I parsed the input file into a string strAll.

Input

strAll contains 10 character long values

"  -24.1189"  (two blanks before value)
"    1.2345"  (four blanks before value)

Output

-24.1189;-24.1189; (...total 120 values...)
-24.1234;-24.1189; (...total 120 values...)
(... total 120 rows ...)

Using Mid hat should be easy to parse: Mid(strAll, 1+i, 10+i), where i is the counter in a for loop. A Replace(stAll, " ", "") should remove all the 3 blanks, 2 blanks and one blank.

Question: How to output the string to a file, formatted like a matrix?

Dim intValueLength, maxValue, intValueInRowMax
intValueLength=10
intValueInRowMax=120
maxValues=intValueInRowMax * intValueInRowMax



Sub Strg2Array
  arrAll = array()

  ' convert to array
      For i=1 To maxValues
        ReDim Preserve arrAll(UBound(arrAll) +1)
        arrAll(UBound(arrAll)) = Mid(strAll, 1+(i-1)*intValueLength, i*intValueLength)
      Next
End Sub

Sub SaveAll
      Dim intValueInRow
      intValueInRow=0
  Const ForWriting = 2
  Set objFSOOut = CreateObject("Scripting.FileSystemObject")
  Set objOutput = objFSOOut.OpenTextFile(strFileName, ForWriting, true)
      for each value in arrAll
        objOutput.Write value
        intValueInRow = intValueInRow + 1  'Argh, there is no "++" operator?
        If (intValueInRow = intValueInRowMax) Then
          objOutput.Write vbNewLine
          intValueInRow=0
        End If
      next
objOutput.Close
Set objFSOOutput = Nothing
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:24:54+00:00Added an answer on June 13, 2026 at 1:24 am

    (Nearly) the same idea as Ansgar, different implementation:

      Const cnRows = 4    ' to keep the demo simple
      Const cnCols = 3
      Const csFSep = ";"
    ' Const csRSep = vbLf
      Dim   csRSep : csRSep = vbLf
    
      Dim aInps : aInps = Array( _
          Join(Array("A1  B1 C1 A2", vbLf, "B2,C2", "comment", vbCrLf, "A3 B3 C3", vbTab, "A4-B4-C4")) _
        , "1 2 3 4 5 6 7 8 9 10 11 12" _
        , Join(Array("1.1 -2.2 3.3 4", vbLf, "0.5 -6.6", "comment", vbCrLf, "7 8.0 -9.99", vbTab, "10.10*11.11***-12.12")) _
      )
      ' no need to care for the input format, as long as the valid data can be
      ' specified by a RegExp pattern (and the file contains 'enough' info)
      Dim reCut : Set reCut = New RegExp
      reCut.Global  = True
      reCut.Pattern = "([A-Z-])?\d+(\.\d+)?"
    
      Dim sInp
      For Each sInp In aInps
          WScript.Echo Join(Array("----", vbCrLf, sInp, vbCrLf, "----"), "")
          Dim oMTS : Set oMTS = reCut.Execute(sInp)
          If oMTS.Count <> cnRows * cnCols Then
             WScript.Echo "Bingo:", oMTS.Count, "<>", (cnRows * cnCols)
          Else
             Dim m
             For m = 0 To oMTS.Count - 1
                 WScript.Stdout.Write oMTS(m).Value
                 If 0 = (m + 1) Mod cnCols Then WScript.Stdout.Write csRSep Else WScript.Stdout.Write csFSep
             Next
          End If
      Next
    

    output:

    ----
    A1  B1 C1 A2
     B2,C2 comment
     A3 B3 C3        A4-B4-C4
    ----
    A1;B1;C1
    A2;B2;C2
    A3;B3;C3
    A4;B4;C4
    ----
    1 2 3 4 5 6 7 8 9 10 11 12
    ----
    1;2;3
    4;5;6
    7;8;9
    10;11;12
    ----
    1.1 -2.2 3.3 4
     0.5 -6.6 comment
     7 8.0 -9.99     10.10*11.11***-12.12
    ----
    1.1;-2.2;3.3
    4;0.5;-6.6
    7;8.0;-9.99
    10.10;11.11;-12.12
    

    My pattern tries to identify the valid data and avoids the (maybe costly) string manipulations.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below are two programs that write 50,000,000 bytes to a file. The first program,
Im having some general confusion with encoding on a little tool I'm writing. First
I'm actually writing a templating tool that will be able to read a test
we currently experience some file writing/encoding problems that we cannot reproduce. Actually there are
I am currently writing a Batch file (first time doing so) to remotely call
I'm trying to learn Lisp (elisp, actually), and I tried writing the following function
Actually I am developing one application in that when application run first time it
I've been stuck on this question for a while. I have a data file
I'm actually writing about the same program as before, but I feel like I've
I'm trying to write a sizable chunk of data to a file that is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.