170 FOR J=1 TO 5
180 PRINT
190 NEXT J
200 REM *********************************
210 DIM A(2),B(2),C(2),D(2,100),E(2,100),F(2,100),G$(100)
220 REM *******ENTER INPUT
230 PI=3.141593
I got error:
Error on line 210: Expected end of line
What does that mean? How can I fix it?
If I remove line 210, I'll get:
Error on line 230: Expected undefined
How can I fix it?
I suspect that the code you have is intended for a different flavor of BASIC. There are a lot of them and they all have their own subtleties. I'll take a guess: the BASIC you're using doesn't allow dimming multiple arrays in one dim statement. Breaking it up into separate colon-separated statements should fix it:
210 DIM A(2): DIM B(2): DIM C(2): DIM D(2,100): DIM E(2,100): DIM F(2,100): DIM G$(100)
If that doesn't fix it, or if you prefer, break it into multiple lines. Then the line number in the new error message should narrow down the problematic part:
210 DIM A(2)
211 DIM B(2)
212 DIM C(2)
213 DIM D(2,100)
214 DIM E(2,100)
215 DIM F(2,100)
216 DIM G$(100)
The accepted answer is is completely right, but to address your second question, I prefer GW-Basic, it was simple and gives you an old timey feel.
To use it you'll need either a 32 bit computer, or a DOS emulator like DOSBox. If you are unsure how to use doxbox, see this article.
To turn off the hotkey strip at the bottom, type in KEY OFF
To save use "save" and to load use "load"
Everything else should be similar to Q-Basic
Related
I'm getting a "Run-time error code '6': Overflow" message on something that is trivial (imo).
Strange problem I'm experiencing here with the code below:
Sub StageSetup()
Dim rLastDataRow As Range
Dim lCount As Long: lCount = 0
Dim lDelta As Long: lDelta = 0
1 With Worksheets("Analyzer")
2 Set rLastDataRow = .Range("A2").End(xlDown)
3 lCount = (rLastDataRow.Row - 2) / 10
4 lDelta = (rLastDataRow.Row - 2)
5 lCount = lDelta / 10
6 End With
End Sub
In debug mode, the problem is occurring on line 5 above which is odd in that it is a simple long division.
Note:
I added line 3 above after the fact just to see what happens when it is done in a single line. That works, but I'd like it to work in the form shown in line 5 as the future mods to this code will involve addition accumulations made to lCount before the division occurs.
rLastDataRow.Row when this happened was 2510 in value which so happen to be an evenly divisible value by 10 (stating the obvious).*
I could use a loop to simulate the division, but what's the point in doing that when a simple divide should suffice.
As can be seen, both lCount and lDelta are of Long type. So, this should have been trivial as there shouldn't be any form of type conversion going on here.
I've tried casting the variable and literal utilizing CLng and also the & (as I've seen in some of the threads but thought that was only meant for non-decimal base representations) in various combinations to no avail. I've also did some casting on line 4 with no effect.
Does anyone have any clue what may be going on here?
basically, I want to reverse the numbers. (in the textbox there will be only 2-digit numbers)
if I have Textbox1.text:
12
2
41
71
70
I want to display in the box (Textbox1.text)
21
2
14
17
70
Function:
Public Shared Function Reverse(num As Integer) As Integer
Dim _reverse As Integer = 0
While num <> 0
_reverse *= 10
_reverse += num Mod 10
num \= 10
End While
Return _reverse
End Function
it should work, it actually works, but I don't know how to arrange it to work in all lines.
For Each lines In TextBox1.Lines
Dim rev = Reverse(lines)
lines.Replace(lines, rev)
Next
This is a perfect example of what happens when people try to write code without knowing what the code is supposed to. What the code is supposed to do is not just the end result but the steps to get there. If you don't know what the steps are then you shouldn't be writing any code because it's unlikely that what you write will do anything useful. Code is simply an implementation of logic so you should be getting the logic down first. It doesn't take any programming experience to work out the logic because we could all do this if it was a manual process and that would be the same logic.
So, what are the steps involved?
Get the lines of the text.
Loop over the lines.
Reverse the current line.
Replace the original line with the result of reversing.
Replace the text with the complete results.
If you actually consider each of those steps, it should be obvious that you cannot use a For Each loop because that will only let you get data out of a list, not put data into it. That would make it obvious that a For loop is the right choice, because will let you get data out and put it in. Now you can write code that actually does something useful.
Dim lines = TextBox1.Lines
For i = 0 To lines.GetUpperBound(0)
Dim line = lines(i)
Dim number = CInt(line)
Dim result = Reverse(number)
lines(i) = result.ToString()
Next
TextBox1.Lines = lines
Simple stuff but, again, if you don't know what the code has to actually do, writing code to do it is a challenge. Always break the problem down into smaller parts first, so you can work on each part individually, and always work out the logic you're trying to implement - and test that logic manually - before trying to write code to implement it.
I have a text document (.txt), there I have n lines that have to be split up, but the point is I don't have delimiter. I know the length of each variable that doesn't change.
For example, the first variable is the from the 25 character to 35; the second one, from 36 to 47; then from 48 to 78, then from 79 to 119, and this until the 360th character of the line.
I guess that the solution is by double loop, one for each line and the other one for each variable, but I cannot get it.
If you need more information just ask, I am completely lost.
Thankfully,
Steps you need to take:
Open the file
Read a line
Confirm the line is 360 characters
Assign chunks of the line to different variables
Do things with the variables
Read another line and repeat until EOF
1 & 2:
Your workbook needs a reference to the Microsoft Scripting Runtime in order to give you access to the FileSystemObject. I'll let you research that.
Create a FileSystemObject and use that to create a TextStream with the path to your file.
currentLine = textStream.ReadLine()
Do Until textStream.EOF
If Len(currentLine) = 360 Then
firstChunk = Mid$(currentLine, 25, 10)
secondChunk = Mid$(currentLine, 36, 11)
thirdChunk = Mid$(currentLine, 48, 30)
fourthChunk = Mid$(currentLine, 78, 30)
' Do stuff with chunks
End If
currentLine = textStream.ReadLine()
Loop
In due course you could get fancy and have an array populated with paired items detailing the starting point of a chunk and how many chars it is, something like:
Dim arrChunkPoints As Variant
Dim arrChunks As Variant
arrChunkPoints = Array(25,10, _
36,11, _
48,30, _
78,30)
ReDim arrChunks(UBound(arrChunkPoints)\2) ' Integer returned
This would allow you to step over the items in arrChunkPoints and populate each element of arrChunks with a section of currentLine using Mid$(), but populated with the values from arrChunkPoints. But this is probably for another day.
I want to create a button in Excel which links to:
http://datafeed.api.productserve.com/datafeed/download/apikey/50f70c7de11f99fe127d7ad4c8e37e31/cid/97,98,142,144,
...
,567,569/fid/4319/columns/merchant_product_id,merchant_category,brand_name,product_name,mpn,search_price,aw_deep_link,specifications,valid_from,valid_to,in_stock,warranty,aw_product_id,merchant_image_url,description/format/csv/delimiter/,/compression/gzip/adultcontent/1/
I've cut out a large section in the middle, but it is just a long sequence of numbers separated by commas. In total the URL is 1939 characters long.
Copying the URL into a browser works fine - it is a download link and the file opens as it should.
The code for the button is simple:
Private Sub download_button_Click()
Dim feed_hyperlink As String
feed_hyperlink = *"http://data... "*
ActiveWorkbook.FollowHyperlink feed_hyperlink
End Sub
When I run the procedure, I get the following error:
Run-time error '5': Invalid procedure call or argument
Hyperlinking a cell restricts the destination URL to 255 characters. Is a character limit what's causing the issue here, or is there another problem?
I think you're right. It's probably too long as the longest one I can use before getting the same error is 1033 characters;
Sub Main()
Dim h As String
h = String(1034, "a")
Debug.Print Len(h)
ActiveWorkbook.FollowHyperlink h
End Sub
I have a text file that has multiple blank lines and Im trying to return all the lines between two of them specifically
so if I have a file that looks like this:
____________________________
1########################
2##########################
3
4########################
5##########################
6#######################
7
8#########################
9##########################
10#######################
11####################
12########################
13#########################
14
15##########################
----------------------------
I would like to grab lines 8-13. Unfortunately, it might not always be 8-13 as it could be 9-20 or 7-8, but it will however always be between the 2nd and 3rd line break.
I know how to trim characters and pull out singular lines, but I have no idea how to trim entire sections.
Any help would be appreciated, even if you just point me to a tutorial.
Thanks in advance.
The basic idea here is to get the entire thing as a string, split it into groups at the double line breaks, and then reference the group you want (in your case, the third one).
Dim value As String = File.ReadAllText("C:\test.txt")
Dim breakString As String = Environment.NewLine & Environment.NewLine
Dim groups As String() = value.Split({breakString}, StringSplitOptions.None)
Dim desiredString As String = groups(2)
MsgBox(desiredString)
Edit:
In response to the question in your comment -
Environment.NewLine is a more dynamic way of specifying a line break. Assuming you're running on windows - you could use VbCrLf as well. The idea is that if you were to compile the same code on Linux, it Environment.NewLine would generate a Lf instead. You can see here for more information: http://en.wikipedia.org/wiki/Newline
The reason I used Environment.NewLine & Environment.NewLine is because you want to break your information where there are two line breaks (one at the end of the last line of a paragraph, and one for the blank line before the next paragraph)
What I ended up doing was trimming the last part and searching for what I needed in the first part (I know I didnt include the searching part in the question, but I was just trying to figure out a way to narrow down the search results as it would have had repeated results). Im posting this incase anyone else stumbles upon this looking for some answers.
Dim applist() = System.IO.File.ReadAllLines("C:\applist.txt")
Dim findICSName As String = "pid"
Dim ICSName As New Regex("\:.*?\(")
Dim x = 0
Do Until applist(x).Contains("Total PSS by OOM adjustment:")
If applist(x).Contains(findICSName) Then
app = ICSName.Match(applist(x)).Value
app = app.TrimStart(CChar(": "))
app = app.TrimEnd(CChar("("))
ListBox1.Items.Add(app)
End If
x = x + 1
Loop
End If
How this works is that it looks through each line for the regex until it reaches first word in the breakpoint "Total PSS by OOM adjustment:"