It is currently Fri May 24, 2013 6:28 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject:
PostPosted: Sun Mar 30, 2003 8:15 pm 
Offline
PureBasic Guru
PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777210
Restored from previous forum. Originally posted by albanread.

;I really like PureBasic a lot and thought I should post something.
;This is a good forum, I learn a lot by reading it.
;So this is a simple IP calculator.
;Cheers
;Alban

;- Window Constants
;
#Window_0 = 0

;- Gadget Constants
;
#Gadget_IP = 0
#Gadget_Calc = 1
#Gadget_SM = 2
#Gadget_CLASS = 3
#Gadget_SLIDER = 4
#Gadget_PREFIX = 5
#Gadget_NETS = 6
#Gadget_HOSTS = 7
#Gadget_10 = 8
#Gadget_11 = 9
#Gadget_INVERT = 10
#Gadget_LIST = 11
#Gadget_14 = 12
#Gadget_15 = 13
#Gadget_16 = 14

;- StatusBar Constants
;
#StatusBar_0 = 0

Procedure Open_Window_0()
If OpenWindow(#Window_0, 247, 50, 351, 460, #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar , "IPcalc")
If CreateStatusBar(#StatusBar_0, WindowID())
EndIf

If CreateGadgetList(WindowID())
IPAddressGadget(#Gadget_IP, 20, 20, 180, 30)
ButtonGadget(#Gadget_Calc, 10, 400, 150, 30, "Calc")
IPAddressGadget(#Gadget_SM, 20, 70, 180, 30)
StringGadget(#Gadget_CLASS, 240, 20, 60, 30, "")
TrackBarGadget(#Gadget_SLIDER, 20, 120, 280, 30, 0, 32)
StringGadget(#Gadget_PREFIX, 240, 70, 60, 30, "")
StringGadget(#Gadget_NETS, 80, 170, 80, 30, "")
StringGadget(#Gadget_HOSTS, 220, 170, 80, 30, "")
TextGadget(#Gadget_10, 20, 170, 40, 30, "Nets")
TextGadget(#Gadget_11, 170, 170, 50, 30, "Hosts")
CheckBoxGadget(#Gadget_INVERT, 320, 70, 20, 30, "")
TreeGadget(#Gadget_LIST, 20, 220, 310, 170)
Frame3DGadget(#Gadget_14, 10, 150, 320, 60, "")
Frame3DGadget(#Gadget_15, 10, 10, 330, 50, "")
Frame3DGadget(#Gadget_16, 10, 60, 330, 50, "")

EndIf
EndIf
EndProcedure


;--------------------------------------- CUT HERE -----------------------
;
;
;
Procedure.l maskToPrefix( c.l )
MOV EBX,c
MOV ECX, 32
XOR EAX, EAX
bitcount:
SHR EBX, 1
ADC EAX, 0
LOOP pbitcount
MOV c, EAX
ProcedureReturn c
EndProcedure


Procedure.l prefix( n.l)
If n.l =0
ProcedureReturn 0
EndIf
ProcedureReturn(-1 32: prefix.l=32:EndIf
bits.l = prefix.l
updateGadgets3(bits.l, reserved.l)

;------------------------------------------------
Case #Gadget_IP
subNet.l=GetGadgetState(#Gadget_IP)
ip0.l = IPAddressField(subNet.l,0)
If ip0.l oldIP0.l
If ip0.l < 127
reserved.l=8
bits.l=8
SetGadgetText(#Gadget_CLASS,"A")
ElseIf ip0.l < 191
bits.l=16
reserved.l=16
SetGadgetText(#Gadget_CLASS,"B")
ElseIf ip0.l < 224
bits.l=24
reserved.l =24
SetGadgetText(#Gadget_CLASS,"C")
ElseIf ip0.l < 239
SetGadgetText(#Gadget_CLASS,"D")
ElseIf ip0.l < 255
SetGadgetText(#Gadget_CLASS,"E")
EndIf
updateGadgets(bits.l, reserved.l)
EndIf
If reserved.l<4: reserved.l=4: EndIf
oldIP0.l = ip0.l
; endcase IP ----------------------------------
Case #Gadget_INVERT
updateGadgets(bits.l, reserved.l)
;endcase INVERT -------------------------------
Case #Gadget_SM
Mask.l = GetGadgetState(#Gadget_SM)
prefix.l = maskToPrefix( Mask.l)
reserved.l = prefix.l
bits.l = prefix.l
updateGadgets2(bits.l, reserved.l)
; ----------------------------------------------
Case #Gadget_LIST
item.l=GetGadgetState(#Gadget_LIST)
text.s=GetGadgetItemText(#Gadget_LIST,item.l,0 )


;------------------------------------------------
Case #Gadget_Calc
updateTree(bits.l, reserved.l)

EndSelect
EndIf
Until Event = #PB_EventCloseWindow
End


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 30, 2003 8:59 pm 
Offline
PureBasic Guru
PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777210
Restored from previous forum. Originally posted by Andre.

Gives a "Can't create the PureBasic exe file! (already running?)" error message :cry: (Inline-ASM is enabled.)

Regards
André

*** German PureBasic Support ***


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 31, 2003 3:59 pm 
Offline
PureBasic Guru
PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777210
Restored from previous forum. Originally posted by albanread.

Sorry I dont understand why.
I paste this back into the editor and it compiles and runs.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 31, 2003 4:25 pm 
Offline
PureBasic Guru
PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777210
Restored from previous forum. Originally posted by Henrik.

hmm
I get the same error as Andre when i try to run it.

Win 98 se. Btw.
Bedst Regards
Henrik


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 31, 2003 7:11 pm 
Offline
PureBasic Guru
PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777210
Restored from previous forum. Originally posted by albanread.

; removed the assembly language routines.
; in the hope it will compile on other peoples machines!


;- Window Constants
;
#Window_0 = 0

;- Gadget Constants
;
#Gadget_IP = 0
#Gadget_Calc = 1
#Gadget_SM = 2
#Gadget_CLASS = 3
#Gadget_SLIDER = 4
#Gadget_PREFIX = 5
#Gadget_NETS = 6
#Gadget_HOSTS = 7
#Gadget_10 = 8
#Gadget_11 = 9
#Gadget_INVERT = 10
#Gadget_LIST = 11
#Gadget_14 = 12
#Gadget_15 = 13
#Gadget_16 = 14

;- StatusBar Constants
;
#StatusBar_0 = 0

Procedure Open_Window_0()
If OpenWindow(#Window_0, 247, 50, 351, 460, #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar , "IPcalc")
If CreateStatusBar(#StatusBar_0, WindowID())
EndIf

If CreateGadgetList(WindowID())
IPAddressGadget(#Gadget_IP, 20, 20, 180, 30)
ButtonGadget(#Gadget_Calc, 10, 400, 150, 30, "Calc")
IPAddressGadget(#Gadget_SM, 20, 70, 180, 30)
StringGadget(#Gadget_CLASS, 240, 20, 60, 30, "")
TrackBarGadget(#Gadget_SLIDER, 20, 120, 280, 30, 0, 32)
StringGadget(#Gadget_PREFIX, 240, 70, 60, 30, "")
StringGadget(#Gadget_NETS, 80, 170, 80, 30, "")
StringGadget(#Gadget_HOSTS, 220, 170, 80, 30, "")
TextGadget(#Gadget_10, 20, 170, 40, 30, "Nets")
TextGadget(#Gadget_11, 170, 170, 50, 30, "Hosts")
CheckBoxGadget(#Gadget_INVERT, 320, 70, 20, 30, "")
TreeGadget(#Gadget_LIST, 20, 220, 310, 170)
Frame3DGadget(#Gadget_14, 10, 150, 320, 60, "")
Frame3DGadget(#Gadget_15, 10, 10, 330, 50, "")
Frame3DGadget(#Gadget_16, 10, 60, 330, 50, "")

EndIf
EndIf
EndProcedure




;--------------------------------------- CUT HERE --------------------------------------------------
; purebasic removed the assembly language.


Procedure.l prefix( n.l)
If n.l =0
ProcedureReturn 0
EndIf
ProcedureReturn(-1 > 1
Next
ProcedureReturn l.l
EndProcedure



Procedure.l reverse( l.l )
a.b=PeekB(@l.l+0)
b.b=PeekB(@l.l+1)
c.b=PeekB(@l.l+2)
d.b=PeekB(@l.l+3)
PokeB(@l.l+0,d.b)
PokeB(@l.l+1,c.b)
PokeB(@l.l+2,b.b)
PokeB(@l.l+3,a.b)
ProcedureReturn l.l
EndProcedure


Procedure.s ipAddressToString( ip.l)
ipStr.s=""
For i.l=0 To 3
ipStr.s=ipStr.s+Str(IPAddressField(ip.l,i))+"."
Next i
ipStr.s=Left(ipStr.s,Len(ipStr.s)-1)
ProcedureReturn ipStr.s
EndProcedure


Procedure updateGadgets( bits.l, reserved.l)
SetGadgetText(#Gadget_PREFIX,StrU(bits.l,#long))
sMask.l=reverse(prefix(bits))
subNet.l = (132: prefix.l=32:EndIf
bits.l = prefix.l
updateGadgets3(bits.l, reserved.l)

;------------------------------------------------
Case #Gadget_IP
subNet.l=GetGadgetState(#Gadget_IP)
ip0.l = IPAddressField(subNet.l,0)
If ip0.l oldIP0.l
If ip0.l < 127
reserved.l=8
bits.l=8
SetGadgetText(#Gadget_CLASS,"A")
ElseIf ip0.l < 191
bits.l=16
reserved.l=16
SetGadgetText(#Gadget_CLASS,"B")
ElseIf ip0.l < 224
bits.l=24
reserved.l =24
SetGadgetText(#Gadget_CLASS,"C")
ElseIf ip0.l < 239
SetGadgetText(#Gadget_CLASS,"D")
ElseIf ip0.l < 255
SetGadgetText(#Gadget_CLASS,"E")
EndIf
updateGadgets(bits.l, reserved.l)
EndIf
If reserved.l<4: reserved.l=4: EndIf
oldIP0.l = ip0.l
; endcase IP ----------------------------------
Case #Gadget_INVERT
updateGadgets(bits.l, reserved.l)
;endcase INVERT -------------------------------
Case #Gadget_SM
Mask.l = GetGadgetState(#Gadget_SM)
prefix.l = maskToPrefix( Mask.l)
reserved.l = prefix.l
bits.l = prefix.l
updateGadgets2(bits.l, reserved.l)
; ----------------------------------------------
Case #Gadget_LIST
item.l=GetGadgetState(#Gadget_LIST)
text.s=GetGadgetItemText(#Gadget_LIST,item.l,0 )


;------------------------------------------------
Case #Gadget_Calc
updateTree(bits.l, reserved.l)

EndSelect
EndIf
Until Event = #PB_EventCloseWindow
End


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 31, 2003 7:30 pm 
Offline
PureBasic Guru
PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777210
Restored from previous forum. Originally posted by Henrik.

Yeps ;o)
Working now..;o)

Bedst Regards
Henrik.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 31, 2003 7:30 pm 
Offline
PureBasic Guru
PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777210
Restored from previous forum. Originally posted by albanread.

I understand now - the original program compiles and runs under 3.61 but fails under version 3.62. I have not read the 3.62 manual yet so dont know why.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 03, 2003 9:53 pm 
Offline
PureBasic Guru
PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777210
Restored from previous forum. Originally posted by cor.

@albanread

Compiles fine here under PB 3.62 win98 se

Thanks. Very nice

Using Windows 98 SE
Registered Purebasic
--------------------------
C. de Visser
Author of Super Guitar Chord Finder
http://www.ready4music.com
http://www.chordplanet.com


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 04, 2003 12:07 pm 
Offline
PureBasic Guru
PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777210
Restored from previous forum. Originally posted by albanread.

Quick note:
In earlier versions the purebasic labels need to be called from
assembler with a prefix p e.g pLABEL1
In the later version you need to stick l_ in front e.g. l_LABEL1.
That is why the first program wont compile on later versions.
Cheers
Alban


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye