InputMap whats next ?

mogenskilde

Member
Licensed User
Longtime User
Hello folks

I'm new in this world and stumpling ahead

I have made an InputMap list, learned to make initialized values false and can run it on my device and select in the list...

rpmprint1.gif


After select and pressing ok, I get an empty screen

Now I would like to show the selected value from the InputMap in a new screen, but can't find out how to do this in the code.

Regards
Mogens
 

Attachments

  • rpm B4A code.zip
    6.2 KB · Views: 251

JesseW

Active Member
Licensed User
Longtime User
This is from the documentation for the Map collection ...

B4X:
 For i = 0 To Map1.Size - 1 
    Dim Key, Value As String 
    Key = Map1.GetKeyAt(i) 
    Value = Map1.GetValueAt(i) 
Next

Substitute matrliste for Map1, change the 'Value' variable to a Boolean, and check value for true/false and act accordingly. This way each time through the loop, you have the material name and its chechmark status. Hope this helps
 
Upvote 0

mogenskilde

Member
Licensed User
Longtime User
Hi JesseW

Thank you for the fast reply.

Well I've put the code as you descripe (check attached), but when pressing OK I get the following screen

rpmprint2.gif


Please notice that I have not "checked" the "mild Steel" but another material.

Hope you have the patience to guide me further

TIA
 

Attachments

  • rpm B4A code2.zip
    6.3 KB · Views: 217
Upvote 0

JesseW

Active Member
Licensed User
Longtime User
Change this line:

dim key, value as boolean

To this:

dim key as string
dim value as boolean
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Another question:
Do you really want that the user can select more than one material.
This is the case with InputMap.
The code to display the selection depends on this.
If only one selection is admitted, you could use a ScrollView view with RadioButtons.
To display the selected material you can use a Label added by code or in the Designer.

Best regards.
 
Upvote 0

JesseW

Active Member
Licensed User
Longtime User
Klaus brought up a valid question: do you want the user of your app to ne able to select more than one item? If not, use InputList instead of InputMap or use Klaus' suggestion. If you really do intend for the user to be able to select many entries at a time, consider using InputMultiList. Here is the link to the InputList in the documentation, and InputMap and InputMultiList are the next two entries. Consider your options, read the help file and decide which is best. Good luck.

Basic4android - Core
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
InputList would be fine.
Some other questions:
- What's the purpose of the program, just for my information. It would be interesting to know the whole goal of the program, so we could give you better advices.
- Do you want the user to select only once the material or should he be able to chage it afterwards ? If yes you should put the material selection in a subroutine so you can call it whenever you want to.
- What do you want to do with the material selection ?
- What other data do you need to be added. Depending on the other data it would be useful to memorise the material index to look up for material parameters.

Best regards.
 
Upvote 0

mogenskilde

Member
Licensed User
Longtime User
Hi Klaus

Thank you very much for your support.

I've been a hobby machinist for many years, and may now be ready to take up the hobby of building applications for smart phones :)

My first attempt, besides the two programs in the beginners guide, is to make an app. that will find the correct speed for your drilling- , Milling- or Lathe machine.

I want to make an app that firstly ask what material one is working with, next input will be the diameter of tool or work piece.

These two inputs can be used to calculate the correct RPM for your machine.

I'm unable to find any exsample code for an InputList event, and my knowlegde is far to little to under stand info like :
InputList (Items As List, Title As String, CheckedItem As Int) As Int

Could you guide me to understand such info.

My experience in programming, well in 1981 I learned PASCAL :) and in 1986 I learned a little BASIC :sign0161: so you can see that I'm a true novice
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Hi Morgens,
Knowing now what you want to do, it's much easier to help you.
I am a mechanical engineer (now retired), so I know what you are speeking of.
I had a look at your site, very interesting :).
Attached you have a first prototype that shows what could be done, I leave the RPM calculation up to you.
I left out any comments to let you analyse the code to 'learn'.

Best regards.
 

Attachments

  • RPM.zip
    6.4 KB · Views: 238
Last edited:
Upvote 0

Wien.Mart

Member
Licensed User
Longtime User
Dear Klaus,

I tried modifying the source you posted here and was able to run it a few times. Now I get an error ArrayIndexOutOfBoundsException: length=0; index=0 . I'm can't seem to get what the error is.

The source code is as follows:

#Region Module Attributes
#FullScreen: False
#IncludeTitle: True
#ApplicationLabel: RPM
#VersionCode: 1
#VersionName:
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region

'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Type Materials(Name As String, CutSpeed As Double) ' here you can add othe parameters
Dim NbMaterials As Int
Dim Material(NbMaterials) As Materials : NbMaterials = 6
Dim SelectedMaterialIndex As String : SelectedMaterialIndex = 0
'added
Dim qcur As Cursor
Dim hhid As Int
Dim sql1 As SQL
Dim t As Phone
Dim DBFileName As String : DBFileName="ichtdb.dbf"
Dim DBFilePath As String : DBFilePath=File.DirRootExternal
'added library sql and phone

End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim spnMaterial As Spinner
Dim edtDiameter As EditText
Dim lblRPM As Label
Dim btnCalculate As Button
End Sub


Sub Activity_Create(FirstTime As Boolean)

Activity.LoadLayout("Main")
'added
If File.Exists(DBFilePath, DBFileName)=False Then
If FirstTime Then
sql1.Initialize(DBFilePath, DBFileName, True)
End If
'SQLCreateTable
Else
If FirstTime Then
sql1.Initialize(DBFilePath, DBFileName, True)
End If
End If
If FirstTime Then
InitMaterial
End If
End Sub

Sub Activity_Resume
InitMaterialSpinner
spnMaterial.SelectedIndex = SelectedMaterialIndex
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub btnCalculate_Click
Dim Diam, CutSpeed, RPM As Double
Diam = edtDiameter.Text
CutSpeed = Material(SelectedMaterialIndex).CutSpeed
RPM = 300 ' just for test
lblRPM.Text = RPM
End Sub

Sub spnMaterial_ItemClick (Position As Int, Value As Object)
SelectedMaterialIndex = Position
End Sub

Sub InitMaterialSpinner
Dim i As Int

spnMaterial.Clear
For i = 0 To NbMaterials - 1
spnMaterial.Add(Material(i).Name)
Next
End Sub
Sub InitMaterial

' Reads the SQL data base
Dim i As Int
' Dim Cursor1 As Cursor
qcur = sql1.ExecQuery("Select description from geocode where type = 5")
'qcur.Position = 0
For i = 0 To qcur.RowCount - 1
'Dim row(NumberOfColumns) As String
qcur.Position = i
Material(i).Name = qcur.GetString("description")
Next
qcur.Close
End Sub
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Instead of posting the code it would be better to post the project as a zip file (IDE menu Files / Export As Zip) with the database so I could test it.
And when you post code please use the code tags [ CODE] [/CODE ] without the spaces.

Looking at your code, I have following comments:
This code is wrong, you set the value of NbMaterials after the Dim statement.
B4X:
Type Materials(Name As String, CutSpeed As Double) ' here you can add othe parameters
Dim NbMaterials As Int
Dim Material(NbMaterials) As Materials : NbMaterials = 6
It must be
B4X:
Type Materials(Name As String, CutSpeed As Double) ' here you can add othe parameters
Dim NbMaterials = 6 As Int
Dim Material(NbMaterials) As Materials
In the Reads the SQL routine you should replace this code:
B4X:
' Reads the SQL data base
Dim i As Int
'Dim Cursor1 As Cursor
qcur = sql1.ExecQuery("Select description from geocode where type = 5")
by this, you don't Dim the Cursor:
B4X:
Dim i As Int
Dim qcur As Cursor
qcur = sql1.ExecQuery("Select description from geocode where type = 5")
In your database what do you have in the description column ?
Where do you read the cut speed, I don't see any CutSpeed column ?

Suggestion for writing SQL queries, I find this better readable :
"SELECT description FROM geocode WHERE type = 5"
than this:
"Select description from geocode where type = 5"

I'm not sure that these suggestions will solve your problem.
 
Upvote 0

Wien.Mart

Member
Licensed User
Longtime User
Dear Klaus, I attached the zip file. I just edited some code from yur original example. It worked a few times then I'm not sure what I did during editing. I'll edit the other sql statements from hereon as you suggested. You are right, it makes it more readable. Thanks in advance.
 

Attachments

  • RPM.zip
    216.3 KB · Views: 179
Upvote 0

klaus

Expert
Licensed User
Longtime User
The problem is that you dimed Material with NbMaterials = 6
But in your database you have 8 items !

Add this code in the InitMaterial routine:
B4X:
NbMaterials = qcur.RowCount
Dim Material(NbMaterials) As Materials
For i = 0 To NbMaterials - 1
 
Upvote 0

Wien.Mart

Member
Licensed User
Longtime User
Thanks Klaus. Yes it works. I will compare with the other one i sent to see where i went wrong. I have one more question, i hope you can help me with. I have a cursor that I want to use to populate an input map with. If I use a hard coded list, it works. I pasted the relevant source code. Please help me. I've been at this since last night ... :oops:

B4X:
    Dim i As  Int
    Dim options As Map
      options.Initialize
    Dim typ As Object
    Dim n As Int
    Dim s As String
   
    Txt = ""
    Txt = "Select * from geopolcode where type = 6"
    QcurExec
    n = qcur.RowCount
      options.Clear   
    For i = 0 To n -1
        s= qcur.GetString("description")
        options.Put(s, False ) ''this is where i am having problems ...
   
    Next
'      scores.Initialize
    InputMap(options, "Ang puno ng pamilyang ito ay:")
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I have not followed your project but you are missing a line. See my code
B4X:
For i = 0 To n -1
        qcur.position=i    'you need add this line
        s= qcur.GetString("description")
                   options.Put(s, False ) ''this is where i am having problems ...   
    Next
 
Upvote 0
Top