New FreeBASIC beginners website

General discussion for topics related to the FreeBASIC project or its community.
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: New FreeBASIC beginners website

Post by dodicat »

Mr Swiss
FbEDIT wasn't inside either of program files.
I had it in a desktop folder.

But I created a folder dev directly on the C: drive, and put fbedit there, and created a shortcut to it on the desktop.
It works now.
Thank you.
owen
Posts: 555
Joined: Apr 19, 2006 10:55
Location: Kissimmee, FL
Contact:

Re: New FreeBASIC beginners website

Post by owen »

thanks for helping dodicat mrswiss. i just uploaded an older version for dodicat in case he wanted to try it.
http://fbcadcam.org/fbedit/old_versions/1067/
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: New FreeBASIC beginners website

Post by MrSwiss »

@dodicat & @owen,

it's been a pleasure, to throw a stone back, into dodicat's garden (aka: return a favour).
He's helped out plenty times before ... just take NOTE of below: (regarding older versions of FBEdit)
MrSwiss wrote:I'm running FBEdit ver. 1.0.7.6c (from german FB site) on WIN10 / 64 with no problems at all ...
REMARK: don't use the not so stable ver.: 1.0.6.8 of FBEdit (I've had crashes with it)!
Franktic
Posts: 18
Joined: Nov 24, 2016 2:35

Re: New FreeBASIC beginners website

Post by Franktic »

Folks, I have a new post showing a random phrase generator http://www.frankticfreebasic.com/2017/0 ... rator.html. I use this generator quite a bit for coming up with various ideas when I write. Let me know what you think.
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: New FreeBASIC beginners website

Post by dodicat »

Yea, nice Franktic.
I would recommend using abstract nouns, they are even more vague.
Your code again:

Code: Select all

'==================================
'Phrase
'module for returning a
'verb adjective noun phrase
'
'Franktic
'
'FreeBasic
'==================================

 Dim asVerb(1 to 100) as String
 Dim asAdjective(1 to 100) as String
 Dim asNoun(1 to 130) as String

 Dim sInputString as String = ""
 Dim iLocation as Integer = 0

 Dim iIndex as Integer = 0


 '==================
 'Fill asVerb array
 '==================
 sInputString = "be have do say go can get would make know will think take see" _
     + " come could want look use find give tell work may should call try ask" _
     + " need feel become leave put mean keep let begin seem help talk turn start" _
     + " might show hear play run move like live believe hold bring happen must" _
     + " write provide sit stand lose pay meet include continue set learn change" _
     + " lead understand watch follow stop create speak read allow add spend grow" _
     + " open walk win offer remember love consider appear buy wait serve die send" _
     + " expect build stay fall cut reach kill remain "

 for iIndex = 1 to 100
     iLocation = Instr(sInputString, " ")
     asVerb(iIndex) = Left(sInputString, iLocation)    
     sInputString = Mid(sInputString, iLocation + 1): Mid(sInputString,1,1)=ucase( Mid(sInputString,1,1))
 next

 '==================
 'Fill asAdjective array
 '==================
 sInputString = "other new good high old great big American small large" _
     + " national young different black long little important political" _
     + " bad white real best right social only public sure low early" _
     + " able human local late hard major better economic strong possible whole" _
     + " free military true federal international full special easy clear recent" _
     + " certain personal open red difficult available likely short single medical" _
     + " current wrong private past foreign fine common poor natural significant" _
     + " similar hot dead central happy serious ready simple left physical general" _
     + " environmental financial blue democratic dark various entire close legal" _
     + " religious cold final main green nice huge popular traditional cultural "
         
 for iIndex = 1 to 100
     iLocation = Instr(sInputString, " ")
     asAdjective(iIndex) = Left(sInputString, iLocation)
 '    print asAdjective(iIndex)
   
     sInputString = Mid(sInputString, iLocation + 1)
 next

 '==================
 'Fill asNoun array
 '==================
 sInputString = _
         "Adoration Amazement Anger Anxiety Apprehension Clarity Delight Despair Disappointment" _
+" Disbelief Excitement Fascination Friendship Grief Happiness Hate Helpfulness Helplessness Infatuation" _
+" Joy Love Misery Pain Pleasure Power Pride Relaxation Relief Romance" _
+" Sadness Satisfaction Silliness Sorrow Strength Surprise Tiredness Uncertainty Wariness Weariness" _
+" Worry Ability Adventure Artistry Awe Belief Chaos Comfort Communication Consideration" _
+" Crime Culture Death Deceit Defeat Democracy Dexterity Dictatorship Disquiet Disturbance" _
+" Dreams Energy Enhancement Failure Faith Faithfulness Faithlessness Favoritism Forgiveness Fragility" _
+" Frailty Freedom Gossip Grace Hearsay Homelessness Hurt Idea Idiosyncrasy Imagination" _
+" Impression Improvement Inflation Information Justice Knowledge Laughter Law Liberty Life" _
+" Loss Luck Luxury Memory Mercy Motivation Movement Need Omen Opinion" _
+" Opportunism Opportunity Parenthood Patriotism Peace Peculiarity Poverty Principle Reality Redemption" _
+" Refreshment Riches Rumor Service Shock Skill Slavery Sleep Sparkle Speculation" _
+" Speed Strictness Submission Success Thought Thrill Truth Unemployment Unreality Victory "

 'sInputString = "time year people way day man thing woman life child world school" _
     '+ " state family student group country problem hand part place case week" _
    ' + " company system program question work government number night point home" _
     '+ " water room mother area money story fact month lot right study book eye" _
     '+ " job word business issue side kind head house service friend father power" _
     '+ " hour game line end member law car city community name president team minute" _
     '+ " idea kid body information back parent face others level office door health" _
     '+ " person art war history party result change morning reason research girl guy" _
     '+ " moment air teacher force education "

 for iIndex = 1 to 129
     iLocation = Instr(sInputString, " ")
     asNoun(iIndex) = Left(sInputString, iLocation)
     sInputString = lcase(Mid(sInputString, iLocation + 1))
 next

'============================================================
'print out a phrase made up of a random: verb + adverb + noun
'============================================================

 Randomize  
  do 
      locate 3
 for iIndex = 1 to 10
     Print asVerb(int(Rnd * 100) + 1) + " " + asAdjective(int(Rnd * 100) + 1) _
         + " " + trim(asNoun(int(Rnd * 129) + 1))+"."
 Next

Sleep
cls
loop until inkey=chr(27)

  
Franktic
Posts: 18
Joined: Nov 24, 2016 2:35

Re: New FreeBASIC beginners website

Post by Franktic »

Great idea! I'll give it a go. Maybe combine both normal and abstract nouns.
Franktic
Posts: 18
Joined: Nov 24, 2016 2:35

Re: New FreeBASIC beginners website

Post by Franktic »

Folks, I've written a new post that discusses #include files and modular programming. http://www.frankticfreebasic.com/2017/0 ... grams.html Please have a look and let me know what you think.
owen
Posts: 555
Joined: Apr 19, 2006 10:55
Location: Kissimmee, FL
Contact:

Re: New FreeBASIC beginners website

Post by owen »

I commented in Franktic's last blog post about the use of "Exit Select" and you know what, even though I have never used an "Exit Select" in my programs, I can see its usefulness...

And this kinda applies to my coding style (behavior) becuase I abuse the Select Case feature.
Some of my sub routines in fbcadcam have dozens of case switches which perhaps could be short circuited so to speak if I were to use a "Exit Select", possibly making my program run faster.

I don't know though. What do you guys think about "Exit Select"?
fxm
Moderator
Posts: 12108
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: New FreeBASIC beginners website

Post by fxm »

I do not see any interest in using Exit Select to get out of a Select Case block, even for an objective of improving runtime.

Indeed, the very principle of the operation of a Select Case block is that as soon as a Case is verified, the corresponding code is executed, and then the tests for the following Case(s) are skipped to go directly to after the End Select instruction.
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: New FreeBASIC beginners website

Post by dodicat »

If you are in a while loop using select case (Most winapi usage does this), then exit select is useful if you suspect an impending illegal call to something.
Non Winapi silly example:

Code: Select all

Screen 19

Print "Use left mouse button sporadically"
Dim As String s
Dim As Long x,y,btn,ctr
While InKey<>Chr(27)
	ctr+=1
	ctr=ctr Mod 2
	GetMouse x,y,,btn
	Select Case btn
		Case 1
			Line-(x,y)	
			Print s
		If Len(s)=0 Then Print "out":Exit select ''dodge an illegal call
		Color 5
		For n As Long=0 To 4
		s[n]=87+39.75*n-18.79*n^2+3.25*n^3-.208*n^4
		Next
		
		Case Else
			Color 15
		If ctr=0 Then s="Hello" Else s=""
					
	End Select
	Sleep 50
Wend
      
fxm
Moderator
Posts: 12108
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: New FreeBASIC beginners website

Post by fxm »

I do not see the improvement compared to using a classic "Else":

Code: Select all

Screen 19

Print "Use left mouse button sporadically"
Dim As String s
Dim As Long x,y,btn,ctr
While InKey<>Chr(27)
   ctr+=1
   ctr=ctr Mod 2
   GetMouse x,y,,btn
   Select Case btn
   Case 1
      Line-(x,y)   
      Print s
      If Len(s)=0 Then
         Print "out" ''dodge an illegal call
      Else
         Color 5
         For n As Long=0 To 4
            s[n]=87+39.75*n-18.79*n^2+3.25*n^3-.208*n^4
         Next
      End If
     
   Case Else
      Color 15
      If ctr=0 Then s="Hello" Else s=""
               
   End Select
   Sleep 50
Wend
Franktic
Posts: 18
Joined: Nov 24, 2016 2:35

Re: New FreeBASIC beginners website

Post by Franktic »

Folks, I have a new post in response to a question asked in an earlier post. The new post simply writes integers into a file, reads them back into an array, then does a little manipulation. http://www.frankticfreebasic.com/2017/0 ... -from.html
Feedback is welcome.
St_W
Posts: 1626
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: New FreeBASIC beginners website

Post by St_W »

Franktic wrote:Feedback is welcome.
Some hints:
- You can declare for-loop-counters in the he header (for x as integer). Additionally setting variables to zero is unnecessary, as that will be done anyway by default. However, it is fine to write it to make it explicit (e.g. for the sum variable; i wouldn't do so for e.g. the myFile variable as that is guaranteed to be overwritten later anyway)
- Integer may be not an optimal choice here, because it has a different size depending on the bitness of the system/compiler.
- the slow thing in your example is the console output (Print Str(x)) rather than the file output. btw, if one wants to write/read really large files it would be adviceable to buffer file I/O, but for your example with not that large files the implementation is fine.
Franktic
Posts: 18
Joined: Nov 24, 2016 2:35

Re: New FreeBASIC beginners website

Post by Franktic »

Thanks St_W. My formal programming training was in the early 90's and, at the time, it was best practice to declare all variables in a group at the top of a program or function and then initialise all of them, even though they would be overwritten. Current thinking, and logically so, is that variables should be declared closer to where they are used. This also make reading larger programs easier because you don't have to scroll up to the variables section to find the relevant information.
Integer is not the best option for variable type in the given example, but is probably the most commonly used. If space was a consideration a smaller variable type would have been used.
The program was written as an example so speed was not really an issue. I don't like programs that leave you with no indication of what is going on. Hence I prefer to have a print statement, even if it is to print a full stop every iteration. I then know the program is working. This is useful when developing but would be removed if the application was going to be used seriously.
Always something new to learn :-)
St_W
Posts: 1626
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: New FreeBASIC beginners website

Post by St_W »

Franktic wrote:Integer is not the best option for variable type in the given example, but is probably the most commonly used. If space was a consideration a smaller variable type would have been used.
It's not about space, but about 32/64-bit compatibility. If you use the wrong variable types your programs may crash on a different platform (for example 64-bit instead of 32-bit). And Integer is especially tricky because it is 32-bits on a 32-bit platform and 64-bits on a 64-bit platform. That is why one should be very careful when using Integer. If you want a fixed-size data type (like for writing something to a file, which should not be platform dependent usually) use e.g. Long or (better readable) Integer<32>.
I just wanted to make you aware that choosing the correct data type is very important and this should be done correctly - especially in a Tutorial, which is used by beginners to learn from it.
Post Reply