Wiki Home

Hello World


Namespace: VB
I know that there are always three ways of doing anything in Fox so I thought I'd ask the delegates on a programming course how many ways they could program "Hello World" in Fox.

These are the one-line ways:
  1. \Hello World && uses set textmerge on, not the same as text..endtext ;-)
  2. ? "Hello world"
  3. Error "Hello World!"
  4. @ x, y SAY "Hello world"
  5. input "Hello World" to x -- wgcs
  6. Wait Window "Hello World"
  7. MessageBox ("Hello World")
  8. SET MESSAGE TO "Hello world"
  9. _screen.Print("Hello World")
  10. ACCEPT "Hello World" TO lcVar && -- Andy Kramek
  11. _screen.Caption="Hello world"
  12. _vfp.StatusBar = "Hello World"
  13. InputBox("?","Hello World","") && -- Andy Kramek
  14. KEYBOARD "{Ctrl+F2}Hello world!"
  15. Assert .F. Message "Hello World" && Debugging, not allowed in interactive mode
  16. DEFINE PAD HelloWorld OF _MSYSMENU PROMPT "Hello World"
  17. MODIFY FILE "Hello World." && -- Geoff Franklin - wishing he hadn't started this.
  18. WAIT "Hello World" TO lcVar && -- And before you ask: No, it's not the same as WAIT WINDOW Mike Lewis
  19. @ x, y GET HelloWorld DEFAULT "Hello World"
  20. ? CHRTRAN(CHRTRAN('67882 3258D', '6789', 'HELP()'), '12345','POWER()')
  21. select '' as Helloworld from (_foxcode) where .f. && -- Phil Spencer
  22. oResponse.Write([Hello World]) && (to web browser from VFP/IIS) -- Claude Fox
  23. SELECT "HelloWord" AS HelloWorld FROM (SYS(2005)) WHERE RECNO() = 1 && -- Luis Maria Guayan

Can it be obtained from a Web Service in one line? -- Alan Bourke

The many multiline ways:

One of the most fundamental building blocks in VFP is the lowly .PRG file. So, you could do ...

HELLOWORLD.PRG
RETURN "Hello World"


This can be called from any other code or the command window like this...

Do HelloWorld.PRG
?HelloWorld()
a=HelloWorld()


Which makes besides making the calling code easy to read, also makes for a reusable, encapsulated design, no?-- Mike Yearwood
Straight out
TEXT
Hello World!
ENDTEXT


SET TALK ON
SET STATUS BAR OFF
HelloWorld = "Hello World"


FoxTools~!~!stripIg_5GU0ED9XP

Debugout:
Activate Window "debug output"
Debugout "Hello World"


Addobject:
_screen.AddObject("lbl","Label")
_screen.lbl.Caption="Hello world"
_screen.lbl.Visible=.t.


Hook to the file system
STRTOFILE("Hello World", "c:\hw.txt")
!TYPE c:\hw.txt


Fox is data, nothing but data:
Create Cursor hello(world C(12))
Insert into hello(world) values("Hello World")
Browse

CREATE CURSOR dummy (dummy L)
APPEND BLANK
SELECT "Hello World" FROM dummy WHERE RECNO() = 1 TO SCREEN



OO way:
Define Class hello As form
    Add Object "world" as label with caption="Hello World!", visible=.T.
EndDefine
oForm = NewObject("hello")
oForm.Show()


Automation:
ie = CreateObject("InternetExplorer.Application")
ie.Navigate("about:blank")
doc = ie.Document
body = doc.body
body.innerHTML = "Hello World"
ie.Visible = .T.


The above can be shortened... - Sietse Wijnker
ie = CreateObject("InternetExplorer.Application")
ie.Navigate("about:Hello World!")
ie.Visible = .T.



Scripting:
shell = NewObject("WScript.shell")
shell.Popup("Hello World")


A windows solution:
DEFINE WINDOW HelloWorld FROM 1,1 TO 2,10 TITLE "Hello World"
ACTIVATE WINDOW HelloWorld

--RushStrong

Balloon tip (WinXP and VFP8+):
Set Classlib To Home()+"samples\solution\toledo\systray.vcx"
oSystray = NewObject("systray")
oSystray.iconfile = HOME()+"Graphics\Icons\Misc\Face02.ico"
oSystray.addicontosystray()
oSystray.showballoontip("Hello World!")


AJAX in action:
http = CreateObject("Msxml2.XmlHttp")
http.open("GET", "http://www.georgenava.com/samples/hello.txt", .F.)
http.send(null)
* ? http.responseText && already used
_vfp.StatusBar = http.responseText



The weirdest?
Md \HelloWorld
Cd \HelloWorld
Cd
Cd \
Rd \HelloWorld


And you thought there were no more:
HelloWorld = "Hello World"
Display Memory like HelloWorld


How about some magic?
oMerlin = NewObject("_agent",Home()+'ffc/_agent.vcx')
oMerlin.load("Merlin","merlin.acs")
oMerlin.setActiveAgent("Merlin")	
oMerlin.show(Rand() * 400, Rand() * 400)
oMerlin.speak("Hello World")
oMerlin.hide()
Release oMerlin
More Automation:
oW = CreateObject("Word.Application")
oW.TypeText("Hello World")
oW.Visible = .T.


And even more automation: -- Sietse Wijnker
ox = CREATEOBJECT("SAPI.SpVoice.1")
oy = ox.GetVoices()
ox.Voice = oy.Item(1)
ox.Speak("Hello world!")
ox.Voice = oy.Item(2)
ox.Speak("Hello world to you too!")


Already suggested :-(
On Error ? "Hello World"
WTF?

On Error


Using the windows API:
DECLARE INTEGER MessageBox IN user32 AS Mbox;
	INTEGER hwnd,;
	STRING lpText,;
	STRING lpCaption,;
	INTEGER wType
MBox(_VFP.hWnd, "Hello world", "anyone out there?", 64)


Ridiculous recursive solution:

?recurse('hello world')

function recurse(stuff)
?? substr(stuff,1,1)
if len(stuff) > 1
	recurse(substr(stuff,2))
endif


In your config.fpw
TITLE = Hello World

-- Kurt

For a more generic approach...
CLEAR
FOR i = 1 TO 31 STEP 3
  ?? CHR(VAL(SUBSTR("072101108108111032087111114108100",i,3)))
ENDFOR

-- Supinski

Hello Graphic World:
Dimension x[9]
x[1] = "20 21 22 29 30 31 83 84 85 95 96 103"
x[2] = "1 2 3 6 7 8 22 31 54 55 56 60 61 62 85 96 103"
x[3] = "2 7 22 31 55 58 61 85 96 103"
x[4] = "2 7 12 13 14 15 22 31 39 40 41 42 55 58 61 66 67 68 69 74 75 77 78 79 85 92 93 94 96 103"
x[5] = "2 3 4 5 6 7 11 16 22 31 38 43 55 57 59 61 65 70 75 76 85 91 95 96 103"
x[6] = "2 7 11 12 13 14 15 16 22 31 38 43 55 57 59 61 65 70 75 85 91 96 103"
x[7] = "2 7 11 22 31 38 43 55 57 59 61 65 70 75 85 91 96"
x[8] = "2 7 11 16 22 31 38 43 55 57 59 61 65 70 75 85 91 95 96 102 103 104"
x[9] = "1 2 3 6 7 8 12 13 14 15 19 20 21 22 23 24 25 28 29 30 31 32 33 34 39 40 41 42 56 60 66 67" + ;
         " 68 69 74 75 76 77 78 82 83 84 85 86 87 88 92 93 94 96 97 102 103 104"

Clear
For i=1 to 9
    n = ALines(y,x[i],.T.," ")
    For j=1 to n
        _screen.PSet(Val(y[j])*3,i*3)
    EndFor
EndFor


Say hello in any language using the INTLToolkit , which works with all of the above, except perhaps Merlin the Magician and the big graphic :-) -- Steven Black
SET PROCEDURE TO INTL ADDITIVE
_SCREEN.AddObject("oINTL", "INTL")
_SCREEN.oINTL.SetLanguage("Spanish")
? I("Hello World")


Hello world overload in a report (supprisingly the first one??) -- Sietse Wijnker
CREATE CURSOR csrTemp (Hello C(10), World C(10))
FOR lnCounr = 1 TO 50
	INSERT INTO csrTemp VALUES ("Hello", "World!")
NEXT
CREATE REPORT HelloWorld.frx FROM csrTemp COLUMN
REPORT FORM HelloWorld.frx PREVIEW
ERASE HelloWorld.fr*


Maybe using intellisense
INSERT INTO (_foxcode) ;
(type, abbrev, cmd, case, save, timestamp, uniqueid) VALUES ;
('U', 'HW', [? "Hello World"], 'U', .T., DATETIME(), SYS(2015))
KEYBOARD "{ctrl+f2}HW "+CHR(13)


Table structure?
* not Hello World - there's no space
* but some other examples aren't correct in that respect either
CREATE CURSOR test (h1 L, e1 L, l1 L, l2 L, o1 L, _1 L, w1 L, o2 L, r1 L, l3 L, d1 L)
LIST STRUCTURE


Killing the clipboard?
_CLIPTEXT='Hello World'
KEYBOARD '{CTRL+V}'


Using a widely unknown system variable -- ?wOOdy
_SHELL = "? 'Hello World'"


run @echo Hello World -- vt :-)

Config.FPW: -- (c) vt
command=...

? CHR(INT(RAND(37769.1)*26+65))+;
  CHR(INT(RAND()*26+65))+;
  CHR(INT(RAND()*26+65))+;
  CHR(INT(RAND()*26+65))+;
  CHR(INT(RAND()*26+65))+;
  " "+ ;
  CHR(INT(RAND(1612256)*26+65))+ ;
  CHR(INT(RAND()*26+65))+ ;
  CHR(INT(RAND()*26+65))+ ;
  CHR(INT(RAND()*26+65))+ ;
  CHR(INT(RAND()*26+65))

-- Kurt
Category Learning VFP Category 3 Star Topics
( Topic last updated: 2006.09.22 09:14:22 AM )