How to use Variable in a prompt? - octave

I want to take input some integer value and prompt the user to answer the same number of question.
I have used G(kk) = input(["Enter %c Permanant Load", ii]); but getting some error
error shows "implicit conversion from numeric to char"
%% For creating load combinations
ii = input("Number of Permanant Loads");
jj = input("Number of Variable Loads");
for kk = 1:ii
G(kk) = input(["Enter %c Permanant Load", ii]);
endfor
G
Enter 1 Permanant Load
Enter 2 Permenant Load

You need to explicitly convert your numeric value (ii) to a String before you can insert it into a string.
This could be done using the mat2str function.
The following should work correctly:
G(kk) = input(["Enter " mat2str(ii) " Permanant Load"]);
Note:
Although I suspect what you really may want is:
G(kk) = input(["Enter " mat2str(kk) " Permanant Load"]);

Related

GAMS csv read issue

I'm trying to read a .csv file with the following format using MAC:
;lon;lat
0;55,245594;25,066697
1;55,135613;25,070419
2;55,275683;25,203425
What I am doing so far is:
$call csv2gdx coords.csv id=d index=1 values=2..lastCol useHeader=y
sets
i
c /x,y/
;
parameters
dloc(i,c) 'locations'
;
$gdxin clients_csv.gdx
$load ___ ?
What I want to do is read the lat,lon coordinates in the parameter dloc so as for each i to have a pair of coords c, i.e. lat, lon.
Example output:
x y
i1 17.175 84.327
Running your code produces an error from csv2gdx:
*** ErrNr = 15 Msg = Values(s) column number exceeds column count; Index = 2, ColCnt = 1
Per default, csv2gdx expects the entries separated by commas, which you do not have in your data. You could also define semicolon or tab as separator by means of an option, but if the data has really the format you posted, you do not need to call csv2gdx at all. You could just include the data directly like this:
Sets
i
c
;
Table dloc(i<,c<) 'locations'
$include coords.csv
;
Display dloc;
EDIT after change of input data format:
The error message is still the same. And also the reason is the same: You use a different field separator than the default one. If you switch that using the option fieldSep=semiColon, you will realize that also your decimal separator is non-default for csv2gdx. But this can be changed as well. Here is the whole code (with adjusted csv2gdx call and adjustments for data loading). Note that sets i and c get implicitly defined when loading dloc with the < syntax in the declaration of dloc.
$call csv2gdx coords.csv id=d index=1 values=2..lastCol useHeader=y fieldSep=semiColon decimalSep=comma
Sets
i
c
;
parameters
dloc(i<,c<) 'locations'
;
$gdxin coords.gdx
$load dloc=d
Display dloc;
$exit\

Why am I getting type mismatch from label in access form?

I am getting values from labels that are formatted as Percent (0.00%).
Therefore, I cast it to a double CDBL(label.caption) and I get the type-mismatch error.... see my code:
Forms(frmName).Label80.Caption = format(CDbl(Forms(frmName).Label123.Caption) + CDbl(Forms(frmName).Label162.Caption), "Percent")
Originally:
label123 has 10.00% value and label162 has 0.00% value
so if I do cdbl(label123) it gives me 10 (good!)
if I do cdbl(label162) it produces an error
if I do val(label162) it produces an error
I'm thinking it has something to do with 0?? I can't seem to figure this out...
You can also use the Format function to parse the percentage and return a string containing the equivalent value in General Number format, so that it may be successfully converted using the CDbl function, e.g.:
Forms(frmName).Label80.Caption = Format(CDbl(Format(Forms(frmName).Label123.Caption, "General Number")) + CDbl(Format(Forms(frmName).Label162.Caption, "General Number")), "Percent")
The advantage of this method is that the Format function recognises that the string represents a percentage and therefore automatically handles the division by 100:
?Format("10.48%", "General Number")
0.1048
The use of CDbl also allows for regional differences in decimal number representation (e.g. the use of a comma in place of a period) - my thanks to #Gustav for pointing this out.
Try removing the % signs:
Forms(frmName).Label80.Caption = Format(Val(Replace(Forms(frmName).Label123.Caption, "%", "")) + Val(Replace(Forms(frmName).Label162.Caption, "%", "")), "Percent")
Edit:
Using Val, only works having dot (.) as the decimal separator.
For a universal solution, use CDbl or CCur as these convert the localised format correctly where a value formatted as percent may display as 10,48%.
Forms(frmName).Label80.Caption = Format(CDbl(Replace(Forms(frmName).Label123.Caption, "%", "")) + CDbl(Replace(Forms(frmName).Label162.Caption, "%", "")), "Percent")
Use the following template for each label. The evaluate takes care of the percent sign.
L0 = CDbl(Evaluate(Label0.Caption))

How do I pass objects to functions in ooRexx?

I'm a long-time mainframe Rexx programmer who is trying out objects in ooRexx. The results are surprising. For example, here is a program:
#!/usr/bin/rexx
a = .number~new(3.14)
say "a =" a
say "a~val =" a~val
call say_number a
exit 0
say_number:
procedure
parse arg num
say "In say_number"
say "num =" num
say "num~val =" num~val
return
::class number public
::attribute val get public
::method init ; expose val ; use arg val
::method new ; expose val ; use arg val
::method string ; return "'"self~val"'"
The result is:
> number
a = '3.14'
a~val = 3.14
In say_number
num = '3.14'
18 *-* say "num~val =" num~val
8 *-* call say_number a
REX0097E: Error 97 running /home/tony/bin/.scripts/number line 18: Object method not found
REX0476E: Error 97.1: Object "'3.14'" does not understand message "VAL"
It appears that the object is being resolved to its string value before it's passed to the say_number function. Weird! Am I missing something obvious?
Well, that didn't take long. I changed parse to use in the function, and everything worked as expected. Per the Reference manual:
USE ARG retrieves the argument objects provided in a program, routine,
function, or method and assigns them to variables or message term
assignments.
PARSE assigns data from various sources to one or more variables
according to the rules of parsing. ... If you specify UPPER, the
strings to be parsed are translated to uppercase before parsing. If
you specify LOWER, the strings are translated to lowercase. Otherwise
no translation takes place.
Presumably PARSE converts the arguments to a string so that it can change case as requested (or defaulted).

Update a multi-valued column through checkbox values

I have recently started using Access with VBA.
Problem Statement : There are 4 optional subjects say Maths,Economics,Computer Science,Home Science. A column called 'Subject' for each student stores the optional subjects(the number of subjects varies with each student).
What I did : I made a multi-valued field in the table called 'Subject' using the lookup wizard in design view. In the form view, I have these 4 checkboxes listed to select and submit . When I try writing an update statement for field 'Subject' using the checkbox values it gives me an error.
Is there some other way to solve this problem or can I correct the method I have used?
Thanks !
Create a new table with 2 fields; Student ID and Subject. Write all subjects into that table. When you need to return them, either use a subform (linked on StudentID) or create a pivot table if necessary.
Multi-Value columns are not optimal, they create a lot of problems. If you absolutely must use one, then you need to parse the data when you extract it. When you first write it, you need to write a statement like;
MyStr = ""
If Me.Checkbox1 = True then
MyStr = MyStr & "SomeValue, "
EndIf
If Me.Checkbox2 = True then
MyStr = MyStr & "SomeValue2, "
EndIf
If Me.Checkbox3 = True then
MyStr = MyStr & "SomeValue3, "
EndIf
If Me.Checkbox4 = True then
MyStr = "SomeValue4, "
EndIf
If Len(MyStr) > 2 Then
MyStr = Left(MyStr, Len(MyStr) - 2)
EndIF
What this does is continually append the values you assign to the checkboxes, and then removes the last 2 characters (which should be ", ") so you have a complete string. Then you write MyStr to your Subject field.
When you go to read this info, you'll need to parse it out into an array and work backwards, determining which checkbox should be marked based on the values in your array.

Removing non-alphanumeric characters in an Access Field

I need to remove hyphens from a string in a large number of access fields. What's the best way to go about doing this?
Currently, the entries are follow this general format:
2010-54-1
2010-56-1
etc.
I'm trying to run append queries off of this field, but I'm always getting validation errors causing the query to fail. I think the cause of this failure is the hypens in the entries, which is why I need to remove them.
I've googled, and I see that there are a number of formatting guides using vbscript, but I'm not sure how I can integrate vb into Access. It's new to me :)
Thanks in advance,
Jacques
EDIT:
So, Ive run a test case with some values that are simply text. They don't work either, the issue isn't the hyphens.
I'm not sure that the hyphens are actually the problem without seeing sample data / query but if all you need to do is get rid of them, the Replace function should be sufficient (you can use this in the query)
example: http://www.techonthenet.com/access/functions/string/replace.php
If you need to do some more advanced string manipulation than this (or multiple calls to replace) you might want to create a VBA function you can call from your query, like this:
http://www.pcreview.co.uk/forums/thread-2596934.php
To do this you'd just need to add a module to your access project, and add the function there to be able to use it in your query.
I have a function I use when removing everything except Alphanumeric characters. Simply create a query and use the function in the query on whatever field you are trying to modify. Runs much faster than find and replace.
Public Function AlphaNumeric(inputStr As String)
Dim ascVal As Integer, originalStr As String, newStr As String, counter As Integer, trimStr As String
On Error GoTo Err_Stuff
' send to error message handler
If inputStr = "" Then Exit Function
' if nothing there quit
trimStr = Trim(inputStr)
' trim out spaces
newStr = ""
' initiate string to return
For counter = 1 To Len(trimStr)
' iterate over length of string
ascVal = Asc(Mid$(trimStr, counter, 1))
' find ascii vale of string
Select Case ascVal
Case 48 To 57, 65 To 90, 97 To 122
' if value in case then acceptable to keep
newStr = newStr & Chr(ascVal)
' add new value to existing new string
End Select
Next counter
' move to next character
AlphaNumeric = newStr
' return new completed string
Exit Function
Err_Stuff:
' handler for errors
MsgBox Err.Number & " " & Err.Description
End Function
Just noticed the link to the code, looks similar to mine. Guess this is just another option.