Recent

Author Topic: can any one help me in my little programe here :/ pls guys  (Read 14542 times)

whitehat

  • Jr. Member
  • **
  • Posts: 93
hello guys i work in a project for education i juste use a older version in lazarus and WinCrt lib the problem here is this procedure when i execute him he don't give me the best script like
nav= 2 and navs[1]= 'home' navs[2]='about';navs1[1] = hello.html;navs1[2]='helloagain.html'  then the result will be:
<li><a href="hello.html">homeabout</a></li><li><a href="helloagain.html"></a></li>
and the correct syntax [result] is:
<li><a href="hello.html">home</a></li><li><a href="helloagain.html">about</a></li>
first i think this problem is maked by the old version of lazarus but after that i run it in lazarus 1.6.4-fpc-3.0.2 i find the same problem i realize the problem is in my programe guys i need help to make my code work correctly
Code: Pascal  [Select][+][-]
  1. program best;
  2. uses wincrt;
  3. type
  4. tab=array [1..20] of string;
  5. var
  6. t:tab;
  7. procedure navbar (var t:tab);
  8. var
  9. navk,i,nav:integer;
  10. navx,navx2,navs,navs1:string;
  11. begin
  12. navx:='<ul>';
  13. navx2:='</ul>';
  14. writeln('combient de navBar tu veux?');
  15. readln(nav);
  16. for i:=1 to nav do
  17. begin
  18. insert('<li><a href=""></a></li>',t[13],length(t[13])+1);
  19.  
  20. writeln('donner le nom pour ton navBar exemple (Home,about,news):');
  21. readln(navs);
  22. navk:=pos('</li>',t[13])-4;
  23. insert(navs,t[13],navk);
  24. writeln('donner le nom de page a transfert(extension[html])');
  25. readln(navs1);
  26. insert(navs1,t[13],pos('href=""',t[13])+6);
  27. end;
  28. t[13]:=navx+t[13]+navx2;
  29.  
  30.  
  31. end;
  32.  
  33.  
  34. begin
  35. navbar(t);
  36. write(t[13]);
  37. end.
  38.  
« Last Edit: April 30, 2017, 07:51:20 pm by whitehat »

Handoko

  • Hero Member
  • *****
  • Posts: 5122
  • My goal: build my own game engine using Lazarus
Re: can any one help me in my little programe here :/ pls guys
« Reply #1 on: April 30, 2017, 08:20:43 pm »
Common newbies' mistakes:
- Using bad naming: t, navk, nav, navx, navx2, navs, navs1
- No proper indents and empty lines
- Write the entire code in lower case or upper case

You've been 6 months, but till today you still a newbie because you repeat the same problems again and again. Most of your issues can be spotted and fixed easily if you do fix the 3 issues I mentioned.

Sorry I do not process messy code.

Note:
I don't give you solution, because you will do the same mistakes again. So I gave you advice.

ASerge

  • Hero Member
  • *****
  • Posts: 2212
Re: can any one help me in my little programe here :/ pls guys
« Reply #2 on: April 30, 2017, 08:38:47 pm »
Sorry I do not process messy code.
+1
Offer such a code - it means not respecting the interlocutors.

whitehat

  • Jr. Member
  • **
  • Posts: 93
Re: can any one help me in my little programe here :/ pls guys
« Reply #3 on: April 30, 2017, 08:57:59 pm »
Handoko no you don't undrestand we just take a 5 hours in the week to learn how to program with pascal and 21 hours of Back-end, functionality/scripting javascript and python that's i'm newbiethis is why i'm newbie there's no time but when i stay at home after school i learn it believe me i need your help for more progress i can make the mistake 2 time or 3 time but there's a time i will not make the same mistake 2 time

whitehat

  • Jr. Member
  • **
  • Posts: 93
Re: can any one help me in my little programe here :/ pls guys
« Reply #4 on: April 30, 2017, 09:02:08 pm »
like the last time you when i get some mistake in my code t[11]:=fo1+t[10]+fo2; and you fix it to me i learn for you that you can see it in this code

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: can any one help me in my little programe here :/ pls guys
« Reply #5 on: April 30, 2017, 09:07:55 pm »
Handoko no you don't undrestand we just take a 5 hours in the week to learn how to program with pascal and 21 hours of Back-end, functionality/scripting javascript and python that's i'm newbiethis is why i'm newbie there's no time but when i stay at home after school i learn it believe me i need your help for more progress i can make the mistake 2 time or 3 time but there's a time i will not make the same mistake 2 time
That is imho a lame excuses for not properly formatting your code.

With that statement you say (without actually writing the words): "i do not care wasting other peoples time reading my stuff, and those people that want to help should invest the time to understand my time-limits and fix the faulty formatting".

If you do something, then better do it right from the start ;-).  And for programming that starts with using proper formatting as that prevents a lot of errors that are immediately visible when indentation is correct.

If you do not have the time use a code-formatting tool like this or this.

The advise using proper names for identifiers is also a good one as it will explain the reader what it is actually used for. If you want to obfuscate code, then there are special tools to do that automatically for you. No need to do that manually  ;D

whitehat

  • Jr. Member
  • **
  • Posts: 93
Re: can any one help me in my little programe here :/ pls guys
« Reply #6 on: April 30, 2017, 09:14:02 pm »
what i really want is to be pro in programming i'm newbie that's right and the advise using proper names for identifier is also good with comment for reader to undrestand the objectif of the code   ::)

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: can any one help me in my little programe here :/ pls guys
« Reply #7 on: April 30, 2017, 10:07:38 pm »
As a general remark to your 'problem':

In case you have difficulty understanding the usage of insert and other 'constructions' on strings then might i suggest the use of WriteStr ?

If you want to make the code readable then the use of WriteStr will require you to do a few extra steps, but in doing so that also leads to much clearer code and is more in line with what human do namely writing strings from left to right. (well, in some parts of the world, that is).

Under normal cisrcumstances i would suggest to make use of the function Format but i'm guessing that you are not at liberty to use that function because it is part of unit SysUtils.

In case you insist (which is not wrong) on using Insert, then do it step by step and print out the results by every step you take in your code. Under normal circumstances i would say: use the debugger and see what every variable holds by each line that is being executed. That way you are able to see what your code is actually doing.

Even using the function Concat or the plain '+' operator on strings will lead to code that is clearer to read and more humanly understandable then using the function Insert.
« Last Edit: April 30, 2017, 10:15:44 pm by molly »

Bart

  • Hero Member
  • *****
  • Posts: 5265
    • Bart en Mariska's Webstek
Re: can any one help me in my little programe here :/ pls guys
« Reply #8 on: May 01, 2017, 12:11:43 am »
This is the ouput you expect?

Code: [Select]
combient de navBar tu veux?
2
donner le nom pour ton navBar exemple (Home,about,news):
home
donner le nom de page a transfert(extension[html])
home.html
donner le nom pour ton navBar exemple (Home,about,news):
news
donner le nom de page a transfert(extension[html])
news.html
<ul>
  <li><a href="home.htm"l>home</a></li>
  <li><a href="news.html">news</a></li>
</ul>

Just use plain + to concatenate strings, it's that simple.
Using insert is a sure way to overcomplicate things here.

The url part is just '<a href="' + the name of the file + '">' + the title of that page + '</a>'.

That should be enough to get you going.

Bart

lainz

  • Hero Member
  • *****
  • Posts: 4449
    • https://lainz.github.io/
Re: can any one help me in my little programe here :/ pls guys
« Reply #9 on: May 01, 2017, 12:26:17 am »
Hi white hat. You sent me a PM to see if I can help you.

I think Bart comment is the solution. But read every single comment they are giving you a lot of good points.

PD: you know how to do a for loop?
« Last Edit: May 01, 2017, 12:32:06 am by lainz »

jmm72

  • Jr. Member
  • **
  • Posts: 79
  • Very experienced in being a beginner...
Re: can any one help me in my little programe here :/ pls guys
« Reply #10 on: May 01, 2017, 12:39:57 am »
Hi white hat. You sent me a PM to see if I can help you.

I think he has PM'ed everyone who has answered to any of his threads in the last month. That alone should be worth a warning.
Lazarus 1.6.4 + FPC 3.0.2 64bits under Windows 7 64bits
Only as a hobby nowadays
Current proyect release: TBA

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: can any one help me in my little programe here :/ pls guys
« Reply #11 on: May 01, 2017, 12:59:00 am »
TRY THIS ...

Code: Pascal  [Select][+][-]
  1. PROGRAM NavBar;
  2. {$APPTYPE CONSOLE} // INSIDE LAZARUS IDE
  3.  USES Keyboard, Classes, Crt;
  4.  
  5.  VAR
  6.   Key: TKeyEvent;
  7.   strNavBar, strWebPage: String;
  8.   slStrings: TStringlist;
  9.   booClose: Boolean;
  10.  
  11.  Function Quit: Boolean;
  12.   Begin
  13.    Result:= False;
  14.     InitKeyBoard;
  15.  
  16.     Key:= GetKeyEvent;
  17.     Key:= TranslateKeyEvent(Key);
  18.  
  19.     If GetKeyEventChar(Key) = #27 // ESC
  20.     Then Result:= True;
  21.  
  22.    DoneKeyBoard;
  23.   End;
  24.  
  25.  
  26. BEGIN
  27.  slStrings:= TStringlist.Create;
  28.   Try
  29.    While Not booClose
  30.    Do
  31.     Begin
  32.      ClrScr;
  33.      WriteLn('Please type in a NavBar name:');
  34.       ReadLn(strNavBar);
  35.  
  36.      WriteLn('Please type in a WebPage name:');
  37.       ReadLn(strWebPage);
  38.  
  39.      slStrings.Add('<li><a href="'+strWebPage+'">'+strNavBar+'</a></li>');
  40.      WriteLn;
  41.  
  42.      WriteLn('Press ESC to show the list or ENTER to input more...');
  43.      If Quit Then Break;
  44.     End;
  45.  
  46.    If slStrings.Text <> ''
  47.    Then
  48.     Begin
  49.      ClrScr;
  50.       WriteLn(slStrings.Text);
  51.       WriteLn;
  52.  
  53.       WriteLn('Press ENTER to quit...');
  54.      ReadLn;
  55.     End;
  56.   Finally
  57.    slStrings.Free;
  58.   End;
  59. END.              
  60.  

By the way: Normally I don't do console apps... for better editing use a GUI !!!
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

lainz

  • Hero Member
  • *****
  • Posts: 4449
    • https://lainz.github.io/
Re: can any one help me in my little programe here :/ pls guys
« Reply #12 on: May 01, 2017, 01:00:32 am »
Handoko no you don't undrestand we just take a 5 hours in the week to learn how to program with pascal and 21 hours of Back-end, functionality/scripting javascript and python that's i'm newbiethis is why i'm newbie there's no time but when i stay at home after school i learn it believe me i need your help for more progress i can make the mistake 2 time or 3 time but there's a time i will not make the same mistake 2 time

Said that before!

Then you will know (or search) how to convert this code to Pascal easily. You sure already know how to create a text file and run this in the browser:

Code: Javascript  [Select][+][-]
  1. <body>
  2.     <script>
  3.         "use strict";
  4.         let pages = prompt("How much links?")
  5.         let site = ['<ul>']
  6.         for (let i = 0; i < pages; i++) {
  7.             let name = prompt(`Insert the name of page number ${i}`)
  8.             let url = prompt(`Insert the url of the page number ${i}`)
  9.             site.push(`<li><a href="${url}">${name}</a></li>`)
  10.         }
  11.         site.push('</ul>')
  12.         document.body.innerHTML = site.join("")
  13.     </script>
  14. </body>

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: can any one help me in my little programe here :/ pls guys
« Reply #13 on: May 01, 2017, 01:14:02 am »
Maybe it's a good idea to use TryFinallyEnd inside the function  :)

Code: Pascal  [Select][+][-]
  1. Function Quit: Boolean;
  2.   Begin
  3.    Result:= False;
  4.     InitKeyBoard;
  5.      Try
  6.       Key:= GetKeyEvent;
  7.       Key:= TranslateKeyEvent(Key);
  8.  
  9.       If GetKeyEventChar(Key) = #27 // ESC
  10.       Then Result:= True;
  11.      Finally
  12.       DoneKeyBoard;
  13.      End;
  14.   End;
  15.  

EDIT:
You can easily load and save the strings if you want...

Code: Pascal  [Select][+][-]
  1. PROGRAM NavBar;
  2. {$APPTYPE CONSOLE} // INSIDE LAZARUS IDE
  3.  USES Keyboard, SysUtils, Classes, Crt;
  4.  
  5.  VAR
  6.   Key: TKeyEvent;
  7.   strNavBar, strWebPage: String;
  8.   slStrings: TStringlist;
  9.   booClose: Boolean;
  10.  
  11.  Function Quit: Boolean;
  12.   Begin
  13.    Result:= False;
  14.     InitKeyBoard;
  15.      Try
  16.       Key:= GetKeyEvent;
  17.       Key:= TranslateKeyEvent(Key);
  18.  
  19.       If GetKeyEventChar(Key) = #27 // ESC
  20.       Then Result:= True;
  21.      Finally
  22.       DoneKeyBoard;
  23.      End;
  24.   End;
  25.  
  26.  
  27. BEGIN
  28.  slStrings:= TStringlist.Create;
  29.   Try
  30.    If FileExists('C:\Users\USER\Documents\NavBar.txt')
  31.    Then slStrings.LoadFromFile('C:\Users\USER\Documents\Navbar.txt');
  32.  
  33.    While Not booClose
  34.    Do
  35.     Begin
  36.      ClrScr;
  37.      WriteLn('Please type in a NavBar name:');
  38.       ReadLn(strNavBar);
  39.  
  40.      WriteLn('Please type in a WebPage name:');
  41.       ReadLn(strWebPage);
  42.  
  43.      slStrings.Add('<li><a href="'+strWebPage+'">'+strNavBar+'</a></li>');
  44.      WriteLn;
  45.  
  46.      WriteLn('Press ESC to show the list or ENTER to input more...');
  47.      If Quit Then Break;
  48.     End;
  49.  
  50.    If slStrings.Text <> ''
  51.    Then
  52.     Begin
  53.      ClrScr;
  54.       WriteLn(slStrings.Text);
  55.       // If you like to save the strings... or let the user type in the path...
  56.       slStrings.SaveToFile('C:\Users\USER\Documents\NavBar.txt');
  57.       WriteLn;
  58.  
  59.       WriteLn('Press ENTER to quit...');
  60.      ReadLn;
  61.     End;
  62.   Finally
  63.    slStrings.Free;
  64.   End;
  65. END.
  66.  

Expand this if you like ...  or better use a GUI  :P
« Last Edit: May 01, 2017, 02:00:52 am by RAW »
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4458
  • I like bugs.
Re: can any one help me in my little programe here :/ pls guys
« Reply #14 on: May 01, 2017, 12:00:48 pm »
Hi white hat. You sent me a PM to see if I can help you.
I think he has PM'ed everyone who has answered to any of his threads in the last month. That alone should be worth a warning.
I am getting PMs, too. I replied and told that this public forum is the right place for such generic help requests.
A personal message is a right channel for personal issues.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

 

TinyPortal © 2005-2018