I know BASIC is a deprecated language but it's fun to play around with. I'm using FreeBASIC on Windows and I'm trying to re-compile an old program that I originally wrote for the Apple ][.
One instruction that no longer works is HOME, which coincidentally HOMEs the cursor. I found this about getting/setting the cursor position in VB.NET, but as I'm using BASIC I assume it will not work.
Therefore, my question is... how can I get/set the cursor position in BASIC?
You can set the cursor position using LOCATE:
CLS
LOCATE 3, 30
PRINT "Hello World"
GETKEY
END
LOCATE can be used as a function as well to detect the current cursor position. But there are also dedicated functions for that, CSRLIN and POS.
Considering that your program is working in a textual environment 25 Lines x 80 Columns (CGA Text Mode 640x200)
Syntax for FreeBASIC
dim as integer column = 0, row = 0 'Set the variable for store the position
dim as string char = "" ' Set a variable for store the pressed key
cls ' Clear the screen
row = csrlin ' read the actual cursor row and store inside the var row
column = pos ' read the actual cursor column and store inside the var column
do until ( char = chr(27) ) ' make a loop until you press ESC key
char = inkey ' store the pressed key in char variable
if not(char = "") Then ' When you press a key and char store the pressed key then start this routine
if not(char = chr(27)) then ' if pressed a key and not are the ESC or Enter or backspace key
if char = chr(13) then ' when press enter
row = row + 1 ' add a new line if enter are pressed
if row > 23 then row = 23 ' put the stop at row 23
column = 0 ' Put the column at beginning
end if
if char = chr(8) then ' when press backspace
locate row, column
print " "
column = column - 2 ' remove a value from column
if column < 0 then column = 0 ' column cant be lower than 0
end if
if column > 79 then column = 79 ' stop the cursor at 79 column
locate row, column ' move the cursor where
print char ' print the key pressed
column = column + 1 ' add a value to the initial value
end if
locate 24,60 : Print "Row:(" & str(Row) & ") Column:(" & Str(Column) & ")" ' this show where the next cha appair
End if
loop
Forgive me if I correct your opinion, but BASIC has evolved like other Programming Languages, VB.NET and FreeBASIC, where you can develop objects, libraries and take advantage of libraries written in other languages like C and C ++, Currently the same FreeBASIC is a Port of C and as like him has the same potential, in fact it is possible to develop applications for graphical and textual environment on Linux and Windows, you can implement libraries to use databases like MySQL and Oracle, also the same FreeBASIC manages multiple threads to run multiple processes simultaneously .
Related
I have a form that is submitted via a website which generates an email. All of the fields from the form are stored in the ASP code as one big string "strMsgInfo". I want to parse the string, find 10 digits in a row, which is the phone number field, and then format those 10 numbers as 000-000-0000 so that when the email comes up on my phone, I can click the phone number instead of having to type it in manually.
I also want to keep the rest of the string in-tact.
Is this even possible?
Yes it is, use a for loop to iterate throught all characters. If the first character is a number, check if the next is one too. Go until you reach 10.
Edit:
for i = 0 to string.length - 1
if checkisnumber(string[i]) then
telnr &= string[i]
continue = true
else
continue = false
end if
if telnr.length = 10 and continue = true then
end for
else
telnr = ""
end if
next
string = string.replace(telnr, telnr.Insert(3, "-").Insert(8, "-")
Note that after you insert at index 3, the second - is not located at 7 but 8, because the string is already increased in length by 1. Because Insert at index x inserts at that position, all characters starting from that position are moved up by one.
Regards,
Niru
Which event should be applied to the combo-box in prorgress 10.2b, so that it drop down. By default, this is the cursor down, but I need it to open by a space, and I just can not figure out how to do it.
I've managed to do it by creating a selection list that's a copy of the list-items in your combo-box.
Here's some code. Assume the combo is called c and the frame is called f. This works even if you have a widget directly under your combo.
def var hSL as handle no-undo. /* Mandatory variable definition in your program */
on ' ' of c do:
create selection-list hSL
assign frame = frame f:handle
col = c:col in frame f
row = c:row in frame f + 1
list-items = c:list-items in frame f
visible = yes
sensitive = true
triggers:
on return persistent run piChoose.
on leave persistent run piLeave.
end triggers.
apply 'entry' to hSL.
end.
procedure piChoose:
assign c:screen-value in frame f = hSL:Screen-value.
assign c.
apply 'leave' to self.
end procedure.
procedure piLeave:
delete object hSL no-error.
end procedure.
Note if you're using list-item-pairs, then the LIST-ITEM-PAIRS attribute should be used where I'm using list-items.
Hope that helps!
I am trying to create dynamically a group of buttons, using this code:
DEFINE VAR temp-hand AS WIDGET-HANDLE.
DEFINE INPUT PARAMETER ipc AS CHARACTER NO-UNDO.
&global-define X VALUE(v + ipc )
CREATE BUTTON temp-hand
ASSIGN
FRAME = FRAME btn-frame:HANDLE
ROW = vdeInicio
COLUMN = 10
WIDTH = 19
LABEL = ipc
SENSITIVE = TRUE
VISIBLE = TRUE
TRIGGERS:
ON CHOOSE PERSISTENT RUN btn-mess IN THIS-PROCEDURE.
END TRIGGERS.
temp-hand:LOAD-IMAGE("imagenes/Entradas").
vdeInicio = vdeInicio + 3.57.
This works when I address a single button widget, also if a write a loop and call a procedure with this code in it, it creates multiple buttons but points to one handle, some told me than creating a temp table and saving there the widget handle may work, but I donĀ“t know how to populate the table with the widget-handle, can you help me with this,
Something like this:
define temp-table tt_buttonList no-undo
field buttonId as integer
field buttonHandle as widget-handle
.
define variable i as integer no-undo.
do i = i to 5:
create tt_buttonList.
tt_buttonList.buttonId = i.
CREATE BUTTON tt_buttonList.buttonHandle
ASSIGN FRAME = FRAME btn-frame:HANDLE /* this is undefined in your example -- I have no idea where it came from */
ROW = i * 4
COLUMN = 10
WIDTH = 19
LABEL = string( i )
SENSITIVE = TRUE
VISIBLE = TRUE
.
end.
I've no idea why you would run code like this from a trigger procedure. While it might "work", mixing UI into db access code like that is really asking for serious trouble.
I have an asp.net 4 textbox control that has it's text being dynamically populated by some java script. A Google Maps call to be exact. It's giving me mileage from 1 point to another. When the text displays, it shows " 234 mi" I need to get rid of the "mi" part of this text because the text is being converted to an Int32 Updating a table in my DB.
Basically I can only have an INT. Nothing else in the text box. How do I get rid of the "mi" at the end of the text?
Thanks
C#
EB
On the postback, before you save it you could:
var saveValue = Int32.Parse(tbTarget.Text.Replace("mi", string.Empty).Trim());
If your working with a variable length of chars (say someone enters miles instead) then your must do a foreach against the string (an array of char) and check isnumeric on each char.
A simple String.Substring works also:
String leftPart = TxtMileAge.Text.Substring(0, txt.IndexOf(' '));
int mileAge = int.Parse(leftPart);
This retrieves the part of the String in the range of 0 - indexOfWhiteSpace and converts it to an int
Edit: Since the value can have decimal places (as you've commented), you need to parse it to double, round it and then cast it to int:
var txtEstDistance = new TextBox() { Text = "40.2 mi" };
String leftPart = txtEstDistance.Text.Substring(0, txtEstDistance.Text.IndexOf(' '));
double distanceMiles = double.Parse(leftPart, System.Globalization.CultureInfo.InvariantCulture);
int oDdstanceMiles = (int)Math.Round(distanceMiles, MidpointRounding.AwayFromZero);
Im looking for help with trying to vary a variable-name in a for loop:
For b = 1 To Count
' the below image_var(b) varible needs to vary on each iteration'
Dim image_var(b) As New LinkedResource(Server.MapPath(myArray(b-1)))
' need also to have the b in myArray(b-1) bit work through the loop too'
' that is I''m after the array index b minus 1'
image_var(b).ContentId = "imageContentId_" + b.ToString
' add the LinkedResource to the appropriate view'
htmlView.LinkedResources.Add(image_var(b))
Next b
Thanks in advance as I can't logon to accept an answer...
Thanks Guffa - my pics are now making it through to the email and showing up.
The (b) in the image_var(b) was just a stub for me too - till I found the code I was after... Am new and didn't even know/realise that it made an array... am a nobb.
Thanks again...
I don't know why you think that you need a separate variable for each instance. The variable just holds a reference to the object, it doesn't matter at all what you call the variable. You can just reuse the same variable for each of the objects:
For b = 1 To Count
Dim image As New LinkedResource(Server.MapPath(myArray(b-1)))
image.ContentId = "imageContentId_" + b.ToString
' add the LinkedResource to the appropriate view'
htmlView.LinkedResources.Add(image)
Next b