Different results running code using F8 and F5

faromic

New Member
Joined
Jun 30, 2009
Messages
30
I have a code (which I've posted below) that is reading in a text file (posted below the code below). The expected result for misc(21) to be displayed by the message box is "". This result is displayed by the msg box when this code is stepped through using F8. If the code is run normally using F5, a different (incorrect) string is displayed by the msg box. The following is displayed



It reads: "Output Path: (Same as Main Directory Path)........." but it should be "".

Code:
'[Currently the form is set up to pull from only one model]
Option Explicit
Public ModelPath1 As String
Public modelPath2 As String
Public forceOutputPath As String
Public numberGroups As Long
Public numGroups As Long

Public groupINT As Long
Public groupName As String
Public IsGroupSelected As String

Public currentPath As String

Public InfoInputData As String
Public numModel As Long

Public HorzAvgDist As Single
Public VertAvgDist As Single
Public fy As Single
Public globalScaleFactor As Single
Public Sv As Single
Public IC As Single
Public groupListInput As String
Public groupListArr

Public skewTol As Single

Public xShearFactor As Single
Public yShearFactor As Single


Public Sub ReadInData()
'[This routine is used to read everything in except group information]
Dim misc() As String
Dim Fnum As Long
Fnum = FreeFile()
currentPath = ActiveWorkbook.Path

ReDim misc(1 To 29)
 
InfoInputData = currentPath & "\WKBK1 Form Data\" & "Copy of InfoInputData-new.txt"

'[Read in data to initialize textboxes
Open InfoInputData For Input As #Fnum
    Input #Fnum, misc(1), numModel, misc(2), misc(3), HorzAvgDist, misc(4), misc(5), VertAvgDist
    Input #Fnum, misc(6), misc(7), fy, misc(8), misc(9), globalScaleFactor, misc(10), misc(11)
    Input #Fnum, Sv, misc(12), misc(13), IC, misc(14), misc(15), skewTol, misc(26), misc(27), xShearFactor, misc(28), misc(29), yShearFactor
    Input #Fnum, misc(16), misc(17), misc(18), ModelPath1, modelPath2, misc(19), misc(20), forceOutputPath
    Input #Fnum, misc(21), misc(22), numberGroups, misc(23), misc(24), misc(25)
Close #Fnum


The file it's reading in is:
HTML:
//Number of Models://
2

//Horizontal distance to interpolate from edge of opening [ft]//
1

//Vertical distance to interpolate from edge of opening [ft]//
2

//Reinforcing Steel yield strength fy [ksi]//
3

//Global scale up factor//
4

//Sv durability factor//
5

//Maximum IC factor//
6

//Element Skew Tolerance//
100

//X-direction In-plane shear factor//
1.2

//Y-direction In-plane shear factor//
1.8

//Model File Paths: (If only one model is used second model line is blank)//
//Static model path is first and dynamic model path is second//
D:\CMRR Post Processing\CMRR VBA\Model\V & V Model (Sloped Roof)_run6.SDB
D:\CMRR Post Processing\CMRR VBA\Model\V & V Model (Sloped Roof)_run6.SDB

//Force Output Path: (Same as Main Directory Path)//
D:\

//Number of Groups In Model://
 5 

//Groups Information://
//(Group Number; Group is Run (T/F); fc[ksi]; top cover [in]; botttom cover [in])//
11001,True,1,1,1
11002,False,2,2,2
11500,True,3,3,3
12001,False,4,4,4
12305,True,4,3,3

I don't understand why I am getting different results when running the code differently? Thanks,
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
It might not be anything to do with the way you are running the code.

Is path of the workbook the code is located in the same as the text file?

If it is try using ThisWorkbook instead of ActiveWorkbook.

PS Why not read the file line by line?
Code:
Public Sub ReadInData()
'[This routine is used to read everything in
Dim misc() As String
Dim Fnum As Long
Dim LineNum As Long
 
    Fnum = FreeFile()

    currentPath = ThisWorkbook.Path

    InfoInputData = currentPath & "\Copy of InfoInputData-new.txt"
 
    Open InfoInputData For Input As #Fnum
 
        While Not EOF(Fnum)

            ReDim Preserve misc(LineNum)

            Line Input #Fnum, misc(LineNum)

            LineNum = LineNum + 1

        Wend
 
    Close #Fnum
 
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,582
Messages
6,179,670
Members
452,936
Latest member
anamikabhargaw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top