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

  • SEARCH
  • Home
  • 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 8582207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:14:09+00:00 2026-06-11T21:14:09+00:00

This code takes a text file as input and stores each line in a

  • 0

This code takes a text file as input and stores each line in a string array, loops through each line and checks a condition and eventually fills the array.

When I try to transfer this one dimensional array to an excel column through the .range method of excel object library it fills all the cells of range with the first value of the array (i.e array(0)).

 sr = openFileDialog1.FileName()
            If (sr IsNot Nothing) Then

            Dim alltextlines() As String = IO.File.ReadAllLines(sr)
            Dim name As String
            Dim isvalid As Boolean
            Dim tempstr() As String
            Dim count As Integer = 0


            For Each myLine In alltextlines
                ReDim Preserve tempstr(count)
                If myLine.Contains(">") And myLine.Contains(" sds dsd") Then

                    isvalid = Integer.TryParse((Microsoft.VisualBasic.Mid(Microsoft.VisualBasic.LTrim(myLine), 3, 1)), 0)

                    If isvalid Then

                        name = Microsoft.VisualBasic.Left(Microsoft.VisualBasic.LTrim(myLine), 5)

                    Else
                        name = Microsoft.VisualBasic.Left(Microsoft.VisualBasic.LTrim(myLine), 7)

                    End If

                    tempstr(count) = name
                    count = count + 1
                End If

            Next
            Dim message As String = String.Join("..", tempstr)
            MsgBox(message)

            Dim oExcel As Object
            Dim oBook As Object
            Dim oSheet As Object

            'Start a new workbook in Excel.
            oExcel = CreateObject("Excel.Application")
            oBook = oExcel.Workbooks.Add
            oSheet = oBook.Worksheets(1)
            oSheet.Range("A1").Value = "SiteNames"
            oSheet.Range("A1:B1").Font.Bold = True
            oSheet.Range("A2").Resize(tempstr.Length).Value = tempstr




            oSheet = Nothing
            oBook = Nothing
            oExcel.Quit()
            oExcel = Nothing
            GC.Collect()


        Else
            MsgBox("TEXT FILE IS EMPTY", MsgBoxStyle.Critical, "Error")
        End If
    End If
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-11T21:14:10+00:00Added an answer on June 11, 2026 at 9:14 pm

    You should pass a bidimensional array to set the range values.
    This complicates your loop to extract only the rows that respect a predefined condition and you are forced to a second loop to fill the bidimensional array

    As an example

    Dim values(5) as string
    values(0) = "Test0"
    values(1) = "Test1"
    values(2) = "Test2"
    values(3) = "Test3"
    values(4) = "Test4"
    
    Dim tempstr(,) As String = new String(values.Length,1) {}
    for x as Integer = 0 to values.Length - 1
        tempstr(x, 0) = values(x)
    next
    
    
    Dim oExcel as Object = CreateObject("Excel.Application")    
    Dim oBook as Object = oExcel.Workbooks.Add 
    Dim oSheet as Object = oBook.Worksheets(1) 
    oSheet.Range("A1").Value = "SiteNames" 
    oSheet.Range("A1").Font.Bold = True 
    Dim r As Range = oSheet.Range("A2").Resize(tempStr.GetLength(0))
    r.Value2 =  tempstr
    oExcel.Visible = true
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem Hello all! I have this code which takes my jpg image loops through
We have a command line exe that takes input from a text file and
The program takes in input a string from a text file like: 2 1.0
i found this code at activestate, it takes a string and prints permutations of
This code takes 3 seconds on Chrome and 6s on Firefox. If I write
I have this small piece of code that basically takes a list and runs
I get this error: TypeError: object.__init__() takes no parameters when running my code, I
I have code, which i want to run, this takes a few mins so
I would like to optimize the following code in R. This loop takes a
So I have a a text file that looks something like this: public >ret

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.