Forum > Beginners
Real numbers in Arrays
speter:
squarepenguin, I think Kays is suggesting something like:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---for i:=first to last do ComboBox.Items.Add(FloatToStr(step + i * step));
cheers
S.
PS: BTW, I think there is a typo in your code:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---for i:=first to last do A[i-first] := step + i * step;Note that dynamic arrays must start at 0(zero).
dseligo:
--- Quote from: squarepenguin on February 08, 2023, 11:56:18 pm ---begin
Setlength(A, Last-first+1);
for i:=first to last do A := step + i * step;
for count := Low(A) to High(A) do ComboBox.Items.Add(FloatToStr(A[count]));
end;
--- End quote ---
Use codetags for source. In code above index i is lost because forum software thinks is italic.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---begin Setlength(A, Last-first+1); for i:=first to last do A[i] := step + i * step; for count := Low(A) to High(A) do ComboBox.Items.Add(FloatToStr(A[count]));end;
Weiss:
--- Quote from: squarepenguin on February 02, 2023, 12:46:27 am ---Hi All,
How can I create an array of floats/real numbers with a step of 0.1, e.g.
Range: [0.1..9]
Steps: 0.1
--- End quote ---
sounds like you were looking for something very matlab/octave/scilab. Like a= [0.1:0.1:9]. Boom! its done. It is built in, part of language. In any other language you are doing it “manually”.
jamie:
And here I thought and fractional index into an array was sought.
In any case, a Advanced Record can be made with Properties, Methodes and operators to create what looks like any form of an array.
Navigation
[0] Message Index
[*] Previous page