1.

Solve : Visual Basic help!!?

Answer» OK i am receiving these errors in my code!!!!

Error1End of statement expected.C:\Users\scott\documents\visual studio 2013\Projects\WindowsApplication2\WindowsApplication2\Form1.vb911WindowsApplication2
Error2Statement is not valid in a namespace.C:\Users\scott\documents\visual studio 2013\Projects\WindowsApplication2\WindowsApplication2\Form1.vb171WindowsApplication2
Error3Statement is not valid in a namespace.C:\Users\scott\documents\visual studio 2013\Projects\WindowsApplication2\WindowsApplication2\Form1.vb661WindowsApplication2
Error4Statement is not valid in a namespace.C:\Users\scott\documents\visual studio 2013\Projects\WindowsApplication2\WindowsApplication2\Form1.vb2121WindowsApplication2
Error5Statement is not valid in a namespace.C:\Users\scott\documents\visual studio 2013\Projects\WindowsApplication2\WindowsApplication2\Form1.vb2511WindowsApplication2
Error6Statement is not valid in a namespace.C:\Users\scott\documents\visual studio 2013\Projects\WindowsApplication2\WindowsApplication2\Form1.vb3671WindowsApplication2
Error7Statement is not valid in a namespace.C:\Users\scott\documents\visual studio 2013\Projects\WindowsApplication2\WindowsApplication2\Form1.vb3771WindowsApplication2





here is my code can anyone please help me!!!!!




Sub [Dim] gNumRows As Long
Dim gDirection As String
Dim gBoxSize As Double
Dim gReversalBox As Integer
Dim gError As Integer
End Sub


Sub GetStock(BYVAL stockSymbol As String, ByVal StartDate As Date, ByVal EndDate As Date, ByVal dest As String, ByVal freq As String)

Dim noErrorFound As Integer
Dim DownloadURL As String
Dim StartMonth, StartDay, StartYear, EndMonth, EndDay, EndYear As String
StartMonth = Format(Month(StartDate) - 1, "00")
StartDay = Format(Day(StartDate), "00")
StartYear = Format(Year(StartDate), "00")
noErrorFound = 0

EndMonth = Format(Month(EndDate) - 1, "00")
EndDay = Format(Day(EndDate), "00")
EndYear = Format(Year(EndDate), "00")
DownloadURL = "URL;http://table.finance.yahoo.com/table.csv?s=" + stockSymbol + "&a=" + StartMonth + "&b=" + StartDay + "&c=" + StartYear + "&d=" + EndMonth + "&e=" + EndDay + "&f=" + EndYear + "&g=" + freq + "&ignore=.csv"

On Error GoTo ErrHandler
With ActiveSheet.QueryTables.Add(Connection:=DownloadURL, Destination:=Range(desti))
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "20"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.REFRESH BackgroundQuery:=False
End With
noErrorFound = 1

ErrHandler:
If noErrorFound = 0 Then
MsgBox("Stock " + stockSymbol + " cannot be found.")
gError = 1
End If

Resume Next
End Sub

Sub DownloadData()

Application.ScreenUpdating = False
Dim freqFlag As String
Dim numRows As Integer
Dim noErrorFoundInDownloadData As Integer
noErrorFoundInDownloadData = 0

On Error GoTo ErrHandlerDownloadData

freqFlag = "m"
If Worksheets("Input").Range("$E$10") = 1 Then
freqFlag = "d"
'plus 2 due to the intitial two rows
numRows = DateDiff("d", Worksheets("Input").Range("$E$8"), Worksheets("Input").Range("$E$9")) + 2
ElseIf Worksheets("Input").Range("$E$10") = 2 Then
freqFlag = "w"
numRows = DateDiff("w", Worksheets("Input").Range("$E$8"), Worksheets("Input").Range("$E$9")) + 2
ElseIf Worksheets("Input").Range("$E$10") = 3 Then
freqFlag = "m"
numRows = DateDiff("m", Worksheets("Input").Range("$E$8"), Worksheets("Input").Range("$E$9")) + 2
End If

If Worksheets("Input").Range("$E$12") = "" Then
noErrorFoundInDownloadData = -1
GoTo ErrHandlerDownloadData
End If


If IsNumeric(Worksheets("Input").Range("$E$12")) Then
gBoxSize = Worksheets("Input").Range("$E$12")
If gBoxSize >= 0.1 And gBoxSize <= 500 Then

Else
noErrorFoundInDownloadData = -1
GoTo ErrHandlerDownloadData
End If
Else
noErrorFoundInDownloadData = -1
GoTo ErrHandlerDownloadData
End If

If Worksheets("Input").Range("$E$13") = "" Then
noErrorFoundInDownloadData = -2
GoTo ErrHandlerDownloadData
End If

If IsNumeric(Worksheets("Input").Range("$E$13")) Then
gReversalBox = Worksheets("Input").Range("$E$13")
If gReversalBox >= 1 And gReversalBox <= 8 Then

Else
noErrorFoundInDownloadData = -2
GoTo ErrHandlerDownloadData
End If
Else
noErrorFoundInDownloadData = -2
GoTo ErrHandlerDownloadData
End If
gReversalBox = Floor(gReversalBox)

Worksheets("DownloadedData").Select()
Worksheets("DownloadedData").UsedRange.Clear()

'Stock 1
If Worksheets("Input").Range("$C$13") <> "NONE" Then
'Cells(1, 1) = Worksheets("Input").Range("$C$13")
'Cells(2, = "Returns"
Call GetStock(Worksheets("Input").Range("$E$11"), Worksheets("Input").Range("$E$8"), Worksheets("Input").Range("$E$9"), "$A$1", freqFlag)
ActiveWindow.SmallScroll Down:=-12
Columns("A:A").TextToColumns(Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), _
Array(7, 1)))
End If

Columns("A:Z").EntireColumn.AutoFit()


Dim vvx As Integer
vvx = Application.Version

If (vvx >= 12) Then
'Excel 2007
ActiveWorkbook.Worksheets("DownloadedData").Sort.SortFields.Clear()
ActiveWorkbook.Worksheets("DownloadedData").Sort.SortFields.Add(Key:=Range("A2:A6550") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal)
With ActiveWorkbook.Worksheets("DownloadedData").Sort
.SetRange Range("A1:G65500")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply()
End With
Else
'Exel 2003
Columns("A:G").Select()
Selection.Sort(Key1:=Range("A2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal)
End If

'If Worksheets("Input").Range("$E$11") = "Y" Then
' Call SwapCloseAndAdjustedClose
'End If
Worksheets("DownloadedData").Select()
Worksheets("DownloadedData").Range("H1").Select()

'Find number of rows
Dim i As Integer
Dim exitloop As Integer
exitloop = 0
i = numRows + 1
Do Until exitloop = 1
If Worksheets("DownloadedData").Cells(i, 1) = "" Then
i = i - 1
Else
gNumRows = i - 1
exitloop = 1
End If
Loop

noErrorFoundInDownloadData = 1
Application.ScreenUpdating = True
ErrHandlerDownloadData:
If noErrorFoundInDownloadData = 0 Then
MsgBox("Error in setting up Download Data.")
Application.ScreenUpdating = True
gError = 1
Exit Sub
ElseIf noErrorFoundInDownloadData = -1 Then
MsgBox("Box Size must be from 0.1 to 500.0.")
Application.ScreenUpdating = True
gError = 1
Exit Sub
ElseIf noErrorFoundInDownloadData = -2 Then
MsgBox("Number of Reversal Boxes must be a number from 1 to 8.")
Application.ScreenUpdating = True
gError = 1
Exit Sub
End If

End Sub

Sub SwapCloseAndAdjustedClose()

Application.ScreenUpdating = False

'Find the number of rows of stock data
M = 2
numRowsData = 0
Do While M < 65000
shtName = outputShtName
If Worksheets("DownloadedData").Cells(M, 1) = "" Then
numRowsData = M - 1 - 1 'Additional Blank Lines
M = 65000
End If
M = M + 1
Loop

Dim vvx As Integer
vvx = Application.Version

If (vvx >= 12) Then
'Excel 2007

Worksheets("DownloadedData").Range("DA1:DA" & numRowsData) = Worksheets("DownloadedData").Range("E1:E" & numRowsData).Value
Worksheets("DownloadedData").Range("E1:E" & numRowsData) = Worksheets("DownloadedData").Range("G1:G" & numRowsData).Value
Worksheets("DownloadedData").Range("G1:G" & numRowsData) = Worksheets("DownloadedData").Range("DA1:DA" & numRowsData).Value
Worksheets("DownloadedData").Range("DA1:DA" & numRowsData) = Worksheets("DownloadedData").Range("DB1:DB" & numRowsData).Value
Else
'Excel 2003

Worksheets("DownloadedData").Range("E1:E" & numRowsData).Copy Destination:=Worksheets("DownloadedData").Range("DA1")
Worksheets("DownloadedData").Range("G1:G" & numRowsData).Copy Destination:=Worksheets("DownloadedData").Range("E1")
Worksheets("DownloadedData").Range("DA1:DA" & numRowsData).Copy Destination:=Worksheets("DownloadedData").Range("G1")
Worksheets("DownloadedData").Range("DB1:DB" & numRowsData).Copy Destination:=Worksheets("DownloadedData").Range("DA1")
End If

Application.ScreenUpdating = True

End Sub

Sub DownloadDataAndChart()
gError = 0
Dim noErrorFoundInCharting As Integer
noErrorFoundInCharting = 0
On Error GoTo ErrHandlerCharting

Dim low As Double
Dim high As Double
Dim lowest As Double
Dim highest As Double
Dim X As Long
Dim y As Long
Dim numOutputRows As Long
Dim prevlowbox As Double
Dim prevhighbox As Double
Dim colCounter As Long

colCounter = 2
numOutputRows = 0
lowest = 0
highest = 0


Call DownloadData()
If (gError = 0) Then
Worksheets("Output").Select()
Worksheets("Output").UsedRange.Clear()

gDirection = "O"
For i = 2 To gNumRows
high = Worksheets("DownloadedData").Cells(i, 3)
low = Worksheets("DownloadedData").Cells(i, 4)
If i = 2 Then
lowest = low
highest = high
Else
If lowest > low Then
lowest = low
End If
If highest < high Then
highest = high
End If
End If
Next i
numOutputRows = Floor(((Floor(highest) + 1) * 2) / gBoxSize) + 1
For i = 1 To numOutputRows
Worksheets("Output").Cells(i, 1) = numOutputRows * gBoxSize - ((i - 1) * gBoxSize)
Worksheets("Output").Cells(i, 1).NumberFormat = "#,##0.000"

Next i
Worksheets("Output").Cells(numOutputRows + 1, 1) = 0
Worksheets("Output").Cells(numOutputRows + 1, 1).NumberFormat = "#,##0.000"

For i = 2 To gNumRows
high = Worksheets("DownloadedData").Cells(i, 3)
low = Worksheets("DownloadedData").Cells(i, 4)
Dim lowvalue As Double
Dim highvalue As Double
Dim lowbox As Double
Dim highbox As Double
lowvalue = Floor(low / gBoxSize) * gBoxSize + gBoxSize
highvalue = Floor(high / gBoxSize) * gBoxSize
lowbox = Floor(lowvalue / gBoxSize)
highbox = Floor(highvalue / gBoxSize)
If i = 2 Then
For j = lowbox To highbox
Worksheets("Output").Cells(numOutputRows + 1 - j, colCounter) = "O"
Next j
prevlowbox = lowbox
prevhighbox = highbox
Else
If gDirection = "O" Then
If lowbox < prevlowbox Then
For j = lowbox To prevlowbox
Worksheets("Output").Cells(numOutputRows + 1 - j, colCounter) = "O"
Next j
prevlowbox = lowbox
ElseIf ((highbox - prevlowbox) >= gReversalBox) Then
colCounter = colCounter + 1
If (colCounter > 12000) Then
noErrorFoundInCharting = 0
GoTo ErrHandlerCharting
End If
gDirection = "X"
For j = prevlowbox + 1 To highbox
Worksheets("Output").Cells(numOutputRows + 1 - j, colCounter) = "X"
Next j
prevhighbox = highbox
End If
Else
If highbox > prevhighbox Then
For j = prevhighbox To highbox
Worksheets("Output").Cells(numOutputRows + 1 - j, colCounter) = "X"
Next j
prevhighbox = highbox
ElseIf ((prevhighbox - lowbox) >= gReversalBox) Then
colCounter = colCounter + 1
If (colCounter > 12000) Then
noErrorFoundInCharting = 0
GoTo ErrHandlerCharting
End If
gDirection = "O"
For j = lowbox To prevhighbox - 1
Worksheets("Output").Cells(numOutputRows + 1 - j, colCounter) = "O"
Next j
prevlowbox = lowbox
End If
End If
End If
Next i

End If 'gError

noErrorFoundInCharting = 1
End Sub

Sub ErrHandlerCharting()
()

If noErrorFoundInCharting = 0 Then
MsgBox("Number of Columns to be plotted on the chart has exceeded 12000. Please reduce the amount of data for charting.")
gError = 1
Exit Sub
End If
End Sub

Function Floor(ByVal X As Double, Optional ByVal Factor As Double = 1) As Double
Floor = Int(X / Factor) * Factor
End Function


Discussion

No Comment Found