I am trying to run a for loop for a backup system and inside that i want to run a SP that will loop. Below is the code that does not work for me..
Any ideas please?
Dim TotalTables As Integer
Dim i As Integer
TotalTables = 10
For i = 1 To TotalTables
objDL.BackupTables(220, i, 001) ' (This is a method from the DL and the 3 parameters are integars)
Next
I tried the SP and it works perfectly in SQLServer
Third parameter is bad, should be:
objDL.BackupTables(220, i, 1)
Related
I have to dim n variables in my software, where n is a number that user types in the interface. I'd start with a for loop, in order to declare these variables, with something like:
for i = 0 to n
dim r.i as IRow = worksheet.CreateRow(i)
next
This is what I think but obviously I know that's wrong. Does anyone knows if this is possible? I can't create neither List(Of) nor arrays because these are rows of an excel file I'm trying to export, otherwise NPOI returns me error.
What does Excel have anything to do with not using a List? You can absolutely use worksheet.CreateRow() with a list:
Dim rows As New List(Of IRow)
For i As Integer = 0 to n - 1
rows.Add(worksheet.CreateRow(i))
Next
Now the name of each row is row(0), row(1), row(2) ... row(n - 1)
If you've tried this and NPOI is giving you an error, you should show that code around where the error is thrown and tell us what the error is.
Based on comments:
'Assuming everything has the same number of entries as ListBox1, per the comments
Dim rows As New List(Of IRow)
Dim row As IRow = worksheet.CreateRow(0)
row.CreateCell(0).SetCellValue("Time")
row.CreateCell(1).SetCellValue("hrr")
For i As Integer = 0 To ListBox1.Items.Count - 1
row = worksheet.CreateRow(i+1)
row.CreateCell(0).SetCellValue(ListBox1.Items(i))
row.CreateCell(1).SetCellValue(ListBox2.Items(i))
rows.Add(row)
Next i
new to SAP but have done some VBA programming.
I need to automate some things in SAP using Excel VBA but I am starting with baby steps and getting stumped.
All I want to do is copy data from a column in SAP (table already open) into an array. Sounds simple. However it starts off well, but never finishes properly. I have a table that has 306 rows. It has gotten stuck at 85, 127, and 178. Not sure if these values mean anything. What's even more puzzling to me is why does it return a value of 0000000127?? I've been looking for an answer for hours.
Running SAP Complex and Excel 2013. Cannot locate SAPfewse.ocx either. I've enabled almost all references in VBA Developer window. Any help/ideas would be much appreciated! I'm hoping it is something obvious.
Set Table = Session.FindById("wnd[0]/usr/cntlDISASSEMBLY_ALV/shellcont/shell")
Dim rows As Long
Dim arrRow() As Variant
Dim colName As String
Dim rowCount As Double
rows = Table.rowCount - 1
ReDim arrRow(rows)
colName = "ZZMRO_CHA"
For j = 0 To rows
arrRow(j) = Table.GetCellValue(j, colName)
Next
Array watch output - "completed" loop
You could try the following:
...
For j = 0 To rows
arrRow(j) = Table.GetCellValue(j, colName)
If j Mod 32 = 0 Then Table.currentCellRow = j
Next
...
Regards, ScriptMan
I've just transferred into a computer class at my high school, we're learning VB 2010. I've been studying hard, but this question has me stumped:
"Two procedures with parameters are shown below. One uses a pre-tested loop and the other uses a post-tested loop. After making the procedure call,
pattern (-2,"####")
The output from each procedure is different.
PRE TESTED
pattern (start as integer, hash as string)
DIM counter as integer
Counter = 0
DO WHILE counter < start
lbldisplay.text = hash
Counter = counter + 1
LOOP
END SUB
POST TESTED
pattern(start as integer, hash as string)
DIM counter as integer
Counter=0
DO
lbldisplay.text = hash
Counter = counter + 1
LOOP WHILE counter > start
END SUB
What would happen in each procedure? What would the result be? I've got my head around some of the basics but this has really stumped me. Thanks!
In Short: a "POST-TESTED" loop will always execute at least once. Where as a "PRE-TESTED" loop may not execute at all.
User defined functions writen in Excel VBA seem to run much slower than functions simply written in the worksheet cells. Is there a way to run them faster? As an example I have a very simple user defined function:
Function myweekday(mydate As Double)
myweekday = Weekday(mydate)
End Function
Basically it does the same thing as the built in =weekday() function. However running this on 50,000 cells takes about 5 seconds to calculate, whereas simply using the built in function takes a fraction of a second.
What can I do to make user defined functions like this run faster?
You can instead pass in the values as a range and have it return all the values at once in an array. I just tried this on 50,000 rows and it returned all the values instantly. You will need to enter the UDF with CTRL + SHIFT + ENTER.
Function myweekday(mydate As Range) As Variant
Dim vMydate As Variant
Dim vMyWeekDay As Variant
Dim i As Long
vMydate = mydate.Value2
ReDim vMyWeekDay(1 To UBound(vMydate), 1 To 1)
For i = 1 To UBound(vMydate)
vMyWeekDay(i, 1) = Weekday(vMydate(i, 1))
Next i
myweekday = vMyWeekDay
End Function
I have this simple function in Excel VBA.
Public Function ubi() As Integer
Dim i As Integer
For i = 7 To 10
If IsNumeric(Cells(35, i).Value) Then
ubi = i
End If
Next
ubi = i
End Function
As you see, the values of i are supposed to be 7 or 8 or 9 or 10. But, when I test the function in the Excel Worksheet I find ubi()=11.
So, What could be the source of error in my code ?
Remove the ubi = i from outside the For...Next loop
The code keeps going while this is true: For i = 7 To 10 Every time you hit this Next it is incremental. When i gets increased to 11, the loop exits - but i is already set to 11.