B4J Question Converting a string to a node name

AlexOfOz

Active Member
Licensed User
I have a reason why I need to build the name of my button, so I can reference the button later in the code and "pull" it to the new location. I can successfully "push" it by clicking in the opposite order, but that is not how the user will want to do it. It's not sensible.

I have successfully built the button name as a string - quite proud of myself - but now I need to use that name to set the new LEFT and TOP of the button. But when I do, the program is seeing it only as a string and won't allow me to set the necessary button parameters.

Is there a command that will help me "convert" the string?

BTW, I'm in the (very) long learning process of creating a sudoku.
 

AlexOfOz

Active Member
Licensed User
You could use a Map, the string as the Key value and the Buttons as the Values.
But, I am interested to know why you need a string for that, the Button has a name so you could use this one.
I expected your question.

The main reason is that I'm still very much a novice. The second reason is that I have 81 buttons and 81 places for them to go. I manage them as an array, and it's in there that the direct connection with the button name is "lost". Instead of BUTTON73 it becomes btn(72). Of course within that section of code the connection is still there, obviously, but once I go across to the section of code that controls where I want the button to go, that connection is lost.

So I need to either convert the string back to the node name OR learn how to use the array in the destination section of code. I've tried that too, but failed :-(
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
What do you mean with: once I go across to the section of code that controls where I want the button to go ?
Is it another Form a code module or a class?
With my suggestion in post#2 you got a solution.
But, I do not like to just answer a question, I prefer trying to help to solve a problem.
Unfortunately, I still do not understand exactly what your problem is.
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
If I get you right:

A view is just a container. If you have multiple buttons, you only need which button was pressed. Here you can "tag" buttons (or other views) with a unique text or number.

You can use btn.tag= "NumberOfButton" and give all buttons the same click event name. In the "click" sub:

So pressing any button leads to the same sub. Here you get the button via the sender parameter.

B4X:
Dim btn as button = sender
log(btn.tag)

So you can identify the button by name (by the tag).
 
Upvote 0

AlexOfOz

Active Member
Licensed User
Klaus, thanks for suggestion to use MAP. I'll give that a try and learn something new.

KMatle, yes, that is the direction I've been working in. I'm using the TAG in the way you suggest.

This forum is great in the help that is provided. I appreciate it.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Can't you post your project showing the problem, so we could see what you have done and how.
I am not convinced that you need to use a Map, but without knowing more precisely your problem it is difficult to give a concrete advice.
 
Upvote 0

AlexOfOz

Active Member
Licensed User
Jose, I have just watched the tutorial, and it is very close to what I need to do, but obviously with some variation. So thank-you very much.

Klaus, I'm a bit of an oddball. It's not that I am keeping anything secret, it's just that I have a particular way of learning. If I post my code up, someone will possibly give me the answer as a done deal, and I won't truly understand what they have done. I will blindly repeat what they show me, but not really learn from it. The advice that yourself and Jose have given me in this post is invaluable, and I thank you for it. I now know about maps and what they do, but not yet any detail. That will come as I dig deeper into them. I also now understand from Jose's link, what that particular tutorial is about. From the tutorial I have learned about lists, which I didn't even know existed, and Erel has shown us examples of what can be done with them. I can see that it will not be a stretch for me to adapt what he showed us to what I want to do. I also now understand the power of the CSSUtils library and will be digging deeper in to that as I progress with my project.

You may have noticed that I haven't once mentioned about how a sudoku program would work, because I imagine that there are sudoku engines out there that I could just plug in. But that's not what I want. Just as I did when I taught myself to draw lines and connect them at a single point, rather than use the canvas DRAWLINE command (which I now use), I want to figure out from scratch how to make a sudoku engine. This will be a 12 month project for me, but at the end of it I will have learned a great deal that I don't currently know.

BTW, my current thinking with the sudoku engine is lots of random number generators, with lots and lots of checking in between, but that is down the track. For now I just want to get the mechanics of the screen working, so I can play with that and make myself feel happy.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Me too, I want to understand what I am doing and why.
And when I try to help I prefer to understand the real problem, before answering a question.
Because quite often the answer would or could be different when the helper knows the real problem.
 
Upvote 0

AlexOfOz

Active Member
Licensed User
A quick update - the help you guys gave mean I've made good advances, so thank-you very much. LIST was the way to go and I'm learning a lot about how it works. I'm now merrily pushing things around the screen.
I have a long, long way to go yet, which will take months, but I'll learn a lot from the effort.

Thanks again.
 
Upvote 0
Top