May 10, 2024, 04:34:40 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


RADIOBUTTON problem

Started by billhsln, December 26, 2007, 02:56:26 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

billhsln

I am trying to set up the second radio button in a group as the default (already selected).  However, in DEBUG mode, it seems that it always gets initialized as Button_1, instead of Button_2.  The problem seems to be in lines 159-166 (CASE BUTTON_1).  I am initializing in lines 92-103 (CASE @IDINITDIALOG).  If I default it to Button_1, then it does not process lines 159-166 (compile program in DEBUG to see).  If it is set to Button_2 then it process's lines 159-166.

I hope someone can tell me what I am doing wrong.

(NOTE: I know that the SORT routine in this program does NOT work, I am trying to figure out how to sort around 2000 file names and using STRING does NOT work (too much space).  Trying ISTRING, but may have to refigure how I am using that. So any hints on that would also be appreciated).

Thanks,
Bill
When all else fails, get a bigger hammer.

LarryMc

I THINK the problem with your "default" button not doing right is that no keystroke/mouseclick is involved.
The only 2 ways that I know of to fix it is:

1. make the 'underscore' button your 1st button in the 'group'
or
2. In your 'process' button routine let the first thing you do is use GETSTATE in a loop to poll the buttons and see which one is set.

Some of the "ace" programmers might know a better way but with my limited skills that is what I would resort to.

As for the sorting of file name entries:

Since they can be rather long sometimes I have done the following in the past:

use the SYSTEM command to run the old DOS directory command on the directory that contains the files you want to sort.
redirect the output of the dir command from the screen to a temp file.
strip the overhead lines and all the files size and date info from the temp file leaving just the file names
use the system command again to run the old DOS SORT command to sort the contents of the temp file to a 2nd temp file.
It sorts pretty fast.
Then have your program read the second temp file to get the file names and they'll be in order as you read them.

Another slight variation is to create a batch file from within your program.  The only line in the batch file that will change is the one that contains the dir you're working on.  Then use the SYSTEM command to run the batch file.

Sounds like a kludge but it has always worked for me reliably.

Like before, I'm a rank amature and some of the experts will have a more "professional" way of getting it done.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

billhsln

Will probably wait on a few more responses before fixing my RADIOBUTTON problem.

However your idea of doing a SYSTEM "DIR /B >ZZZZ.ZZZ" (/B only prints FileNames).  Then doing a "Sort <ZZZZ.ZZZ >ZZZZSORT.ZZZ", seems like an excellent idea.  I will implement that as soon as possible.

Thanks,
Bill
When all else fails, get a bigger hammer.

billhsln

December 26, 2007, 08:47:53 PM #3 Last Edit: December 26, 2007, 08:52:17 PM by billhsln
I had a few problems with the SYSTEM command, but finally got this to work.


/* Q = "  Quote character */
/*   the Quotes are required in case the Subdirectory has blanks in it */
/* Spath is the selected directory path C:\TEMP\NEW DIR\XXX */
Command = Q + Spath + Q
SYSTEM("DS.BAT",Command)


DS.BAT
CD \
CD %1
DIR /A-D-H-S /B >C:\!!ZZZZ.ZZZ
CD \
SORT <!!ZZZZ.ZZZ >!!ZZSORT.ZZZ
DEL !!ZZZZ.ZZZ
EXIT


So, I am sending

DS.BAT "C:\TEMP\NEW DIR\XXX"

I tried doing SYSTEM("DIR",Q+Spath+Q+" /A-D-H-S /B >C:\\!!ZZZZ.ZZZ")
this did not work.

Then I will read !!ZZSORT.ZZZ to get the file names.

Thanks again to Larry for this suggestion, which should work for the SORT of filenames,
Bill
When all else fails, get a bigger hammer.

billhsln

Fixed SORT problem, still looking for info as to why I can't set BUTTON_2 as default for RadioButtons.

This program works pretty much like I want it to, except for having Underscore (_) as Default instead of Space ( ).

Maybe someone can figure that out.

Thanks,
Bill
When all else fails, get a bigger hammer.

grid51

Have you fixed your button problem yet?

I'm not sure but doesn't this work:

You had:
      CASE @IDINITDIALOG
         CENTERWINDOW d1
         SETSTATE d1,BUTTON_1,1
         BSel = 1
         SETSTATE d1,BUTTON_6,1
         SortFls = 0
Change to:
      CASE @IDINITDIALOG
         CENTERWINDOW d1
         SETSTATE d1,BUTTON_2,1
         BSel = 2
         SETSTATE d1,BUTTON_6,1
         SortFls = 0


Steve

billhsln

I changed the setstate d1,BUTTON_2,1 and BSel = 2, but if I don't change anything, I end up with BSel = 1 when I click on PROCESS button.  I added a MESSAGEBOX in the PROCESS button routine to display the value of BSel.  It shows me a 1, not the 2 I expect.

I am uploading my Source code, will appreciate any idea on what I am doing wrong.

Thanks,
Bill
When all else fails, get a bigger hammer.

LarryMc

I'm not so sure you are doing anything wrong.  I think it is a quirk of how a dialog and radiobutton interact.  Only Paul or maybe Sapero can say why.

To make it work I made the following changes:

I made the underscore the first button defined:
CONTROL d1,@GROUPBOX,"Character Selection",50,70,150,150,0x50000007,GROUP_1
CONTROL d1,@RADIOBUTTON,"Underscore _",70,120,87,22,@TABSTOP|@GROUP,BUTTON_2
CONTROL d1,@RADIOBUTTON,"Blank",70,90,70,20,@TABSTOP,BUTTON_1


and to work with it: CASE @IDINITDIALOG
CENTERWINDOW d1
SETSTATE d1,BUTTON_2,1
BSel = 2
SETSTATE d1,BUTTON_6,1
SortFls = 0

After making those changes it works as expected.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

grid51

Hello Bill
I think I've had this same problem.
When your checking for radio buttons starting at line 151 under @controlid the act of checking
activates your statement to set BSel=1 . Those radio buttons seem to be sort of automatic and
can cause problems sometimes.
Maybe you can adjust your code my remming them out starting at line 151. And check thier state
in your process statement.
' CASE BUTTON_1
' IF @NOTIFYCODE = 0
/*button clicked*/
' BSel = 1
' ENDIF
' CASE BUTTON_2
' IF @NOTIFYCODE = 0
/*button clicked*/
' BSel = 2
' ENDIF
' CASE BUTTON_3
' IF @NOTIFYCODE = 0
/*button clicked*/
' BSel = 3
' ENDIF

I ran this with the above change and the messagebox showed BSel =2 so maybe the solution is in
there some where for you.
That's what I did when I had a simular problem.
Hope this helps.
Steve

LarryMc

Steve,
The solution I offered above was based upon my testing in a manner similiar to what you're suggesting.  I also used openconsole and printed variables along the way.

Whatever radiobutton is listed 1st in the group has its'
case button_1st
  if @notifycode=0

fired when the window/controls are built internally.

I really, really think this boils down to the old addage:
QuoteIf it hurts when you do that then don't do that.
Taking my suggestion above allows one to move on to bigger and better things.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

grid51

Hello Larry,
I think we are in agreement sort of, except I tried it your way but then although it selects the
second radio at process it shows the first radio as default so I had to change:
      CASE @IDINITDIALOG
         CENTERWINDOW d1
         SETSTATE d1,BUTTON_2,1
         BSel = 2
         SETSTATE d1,BUTTON_6,1
         SortFls = 0
               to
          CASE @IDINITDIALOG
         CENTERWINDOW d1
         SETSTATE d1,BUTTON_1,1
         BSel = 1
         SETSTATE d1,BUTTON_6,1
         SortFls = 0
cause button 1 is really button 2 and button 2 is really button 1 ,
to make it work. Did you have to do that to?
I think he'll still have to rem out or remove those cases and use checkstate at process unless there's
another way. Otherwise it may be confusing if he has to come back to this code later and things
are switched out of order to make it work. I know it would confuse me as my memory is not that
good.
At any rate, bill may have this all solved by now.
Steve

LarryMc

Yes, I swapped the button names around but the names can always be fixed.

It's just the one that he wants to be the default should be the first CONTROL d1,@RADIOBUTTON,"
after the CONTROL d1,@GROUPBOX,"

Whether he calls that button1 or button50 and sel=1  or select 50.

if he wants button2 and sel=2 to match up he needs to create button2 first.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

grid51

Hello again,
This is what I was talking about:
$MAIN
Def Version$:String
Version$="1.0"
autodefine "off"
CONST EDIT_1 = 2
CONST EDIT_2 = 4
CONST EDIT_3 = 10
CONST GROUP_1 = 41
CONST GROUP_2 = 42
CONST BUTTON_1 = 81
CONST BUTTON_2 = 82
CONST BUTTON_3 = 83
CONST BUTTON_4 = 84
CONST BUTTON_5 = 85
CONST BUTTON_6 = 86
CONST CHOOSE  = 11
CONST PROCESS = 12
CONST QUIT    = 13
CONST cBLACK   = 0
int Infocus, BSel, run, row, i2
int indx, td, SortFls, m
string Spath, sc
DIALOG d1
'declare types and functions
TYPE BROWSEINFO
DEF hOwner:UINT
DEF pidlRoot:UINT
DEF pszDisplayName:POINTER
DEF lpszTitle:POINTER
DEF ulFlags:UINT
DEF lpfn:UINT
DEF lParam:INT
DEF iImage:INT
ENDTYPE

DECLARE IMPORT,SHGetPathFromIDList(pidl:INT,pszPath:STRING),INT
DECLARE IMPORT,SHBrowseForFolder(lpbi:BROWSEINFO),INT
DECLARE IMPORT,CoTaskMemFree(pidl:INT)
DECLARE IMPORT,RtlZeroMemory(pData AS POINTER,length AS INT)
DECLARE IMPORT,SHGetSpecialFolderLocation(hwnd as UINT,nFolder as INT,ppITEMIDLIST as POINTER),int
DECLARE IMPORT, RENAME ALIAS MoveFileA(lpExistingFileName AS STRING,lpNewFileName AS STRING),INT

CREATEDIALOG d1,0,0,350,350,0x80C80080,0,"Split Files based on Character",&d1_handler
CONTROL d1,@SYSBUTTON,"Choose Directory",195,35,120,20,0x50000001,CHOOSE
CONTROL d1,@STATIC,"File Directory",54,14,90,20,0x5000010B,1
CONTROL d1,@EDIT,"No Directory Selected",123,11,200,20,0x50800800,EDIT_1
Spath = ""
CONTROL d1,@STATIC,"Number of Directories",14,39,109,19,0x5000010B,3
CONTROL d1,@EDIT,"7",122,37,30,20,0x50800000,EDIT_2
td = 7
CONTROL d1,@GROUPBOX,"Character Selection",50,70,150,150,0x50000007,GROUP_1
CONTROL d1,@RADIOBUTTON,"Blank",70,90,70,20,@TABSTOP|@GROUP,BUTTON_1
CONTROL d1,@RADIOBUTTON,"Underscore _",70,120,87,22,@TABSTOP,BUTTON_2
CONTROL d1,@RADIOBUTTON,"Dash -",70,150,70,20,@TABSTOP,BUTTON_3
CONTROL d1,@RADIOBUTTON,"Other Char",70,180,70,20,@TABSTOP,BUTTON_4
CONTROL d1,@EDIT,"?",154,180,30,20,0x50810000,EDIT_3
sc = "?"
CONTROL d1,@GROUPBOX,"Sort Files?",50,240,150,50,0x50000007,GROUP_2
CONTROL d1,@RADIOBUTTON,"Yes",70,260,40,20,@TABSTOP|@GROUP,BUTTON_5
CONTROL d1,@RADIOBUTTON,"No",140,260,40,20,@TABSTOP,BUTTON_6
CONTROL d1,@SYSBUTTON,"Process Files",70,310,100,20,0x50000001,PROCESS
CONTROL d1,@SYSBUTTON,"Quit",200,310,50,20,0x50000001,QUIT
run = 1
SHOWDIALOG d1
'process messages until run = 0
WAITUNTIL run = 0
END
'=============
SUB d1_handler
'=============
int z
SELECT @MESSAGE
CASE @IDINITDIALOG
CENTERWINDOW d1
SETSTATE d1,BUTTON_2,1
BSel = 2
SETSTATE d1,BUTTON_6,1
SortFls = 0
CASE @IDCLOSEWINDOW
run = 0
CLOSEDIALOG d1,@IDOK
CASE @IDKEYDOWN
IF GETKEYSTATE(0x2E) AND Infocus = 1
'Process your events
MESSAGEBOX d1, "Delete Key Pressed - 1", "Delete Key Pressed - 1"
ENDIF

IF GETKEYSTATE(0x2E) AND Infocus = 2
'Process your events
MESSAGEBOX d1, "Delete Key Pressed - 2", "Delete Key Pressed - 2"
ENDIF

IF GETKEYSTATE(0x0D) AND Infocus = 2
'Process your events
MESSAGEBOX d1, "Enter Key Pressed - 2", "Enter Key Pressed -2"
ENDIF

IF GETKEYSTATE(0x0D) AND Infocus = 1
'Process your events
MESSAGEBOX d1, "Enter Key Pressed - 1", "Enter Key Pressed - 1"
ENDIF
CASE @IDCONTROL
SELECT @CONTROLID
CASE EDIT_1
/* respond to edit notifications here */
SELECT @NOTIFYCODE
CASE @ENSETFOCUS
Infocus = 1
CASE @ENKILLFOCUS
Infocus = 0
ENDSELECT
CASE EDIT_2
/* respond to edit notifications here */
SELECT @NOTIFYCODE
CASE @ENCHANGE
td = val(GETCONTROLTEXT(d1,EDIT_2))
CASE @ENSETFOCUS
Infocus = 2
CASE @ENKILLFOCUS
Infocus = 0
ENDSELECT
CASE EDIT_3
/* respond to edit notifications here */
SELECT @NOTIFYCODE
CASE @ENCHANGE
sc = GETCONTROLTEXT(d1,EDIT_3)
sc = right$(sc,1)
SETCONTROLTEXT(d1,EDIT_3,sc)
CASE @ENSETFOCUS
Infocus = 3
CASE @ENKILLFOCUS
Infocus = 0
ENDSELECT
          /*****CASE BUTTON_1 through CASE BUTTON_6 Removed > not needed.****/

CASE CHOOSE
IF (@NOTIFYCODE = 0)
' get directory
Spath = GetFolder(d1, "Select directory...")
' if a directory has been selected then continue processing
IF (Spath <> "")
SETCONTROLTEXT(d1,EDIT_1,Spath)
ENDIF
ENDIF
CASE PROCESS

                     /**********ADDED***********/   
                       IF GETSTATE(d1,BUTTON_1)
                          BSel=1
                       ENDIF
                       IF GETSTATE(d1,BUTTON_2)
                          BSel=2
                       ENDIF
                       IF GETSTATE(d1,BUTTON_3)
                          BSel=3
                       ENDIF
                       IF GETSTATE(d1,BUTTON_4)
                          BSel=4
                       ENDIF
                       IF GETSTATE(d1,BUTTON_5)
                          SortFls=1
                       ENDIF
                       IF GETSTATE(d1,BUTTON_6)
                          SortFls=0
                       ENDIF
                     /**************************/

m = messagebox(d1,str$(BSel),"BSel",@MB_YESNO|@MB_ICONEXCLAMATION)
IF m = @IDYES
IF (@NOTIFYCODE = 0)
IF td = 0 THEN td = 7
IF (Spath <> "")
IF (SortFls = 0)
MoveFiles(Spath)
ELSE
SYSTEM("DS.BAT","\"" + Spath + "\"")
messagebox(d1,"Wait for File to be Created","File",@MB_OK|@MB_ICONEXCLAMATION)
SMoveFiles(Spath)
messagebox(d1,"Move Done","Move",@MB_OK|@MB_ICONEXCLAMATION)
z = DELETEFILE("C:\\!!ZZSORT.ZZZ")
ENDIF
run = 0
CLOSEDIALOG d1,@IDOK
ENDIF
ENDIF
ENDIF
CASE QUIT
run = 0
CLOSEDIALOG d1,@IDOK
ENDSELECT
ENDSELECT
RETURN
ENDSUB

'============================
sub MoveFiles(path as string)
'============================
def filename, npath, temp, f$:string
def hfile, dir, attrib, res, f, i, Z:int
def spcl, prev, curr:string

prev = ""
curr = ""

if (td > 99) then
messagebox(d1,"Too many directories, only 99 allowed","Error",@MB_OK|@MB_ICONEXCLAMATION)
return
endif

for i = 1 to td
f$ = ltrim$(str$(i))
if (len(f$) < 2) then f$ = "0" + f$
temp = path + "\\" + f$
f = CREATEDIR(temp)
if (f = 0) then
messagebox(d1,"Problem--Directory not created " + temp,"Error",@MB_OK|@MB_ICONEXCLAMATION)
Return
endif
next i

$IFDEF DEBUG
DEBUGPRINT "BSel=" + STR$(BSel)
$ENDIF

SELECT BSel
CASE 1
spcl = " "
CASE 2
spcl = "_"
CASE 3
spcl = "-"
CASE 4
spcl = sc
ENDSELECT

'f = td + 1
f = 1
f$ = "01"

path += "\\"

temp = path + "*.*"

dir = findopen(temp)
if (dir)
do
filename = findnext(dir,attrib)
if (attrib & @file_directory)
z = 0
else
if (filename <> "")
z = instr(filename, spcl)
if (z <> 0)
curr = left$(filename, z)
if (prev = "") then prev = curr
if (prev <> curr)
f++
if (f > td) then f = 1
f$ = ltrim$(str$(f))
if (len(f$) < 2) then f$ = "0" + f$
endif
npath = path + f$ + "\\"
res = RENAME(path + filename, npath + filename)
if (res)
Z = 1
else
messagebox(d1,filename + " Not MOVED " + path + " - " + npath,"Error",@MB_OK|@MB_ICONEXCLAMATION)
endif
endif
endif
endif
until filename = ""
findclose dir
return
endif
endsub

'=============================
sub SMoveFiles(path as string)
'=============================
def iFile:file
def filename, npath, temp, f$, st:string
def hfile, dir, attrib, res, f, i, Z, max, swap, disp:int
def spcl, prev, curr:string

prev = ""
curr = ""

if (td > 99) then
messagebox(d1,"Too many directories, only 99 allowed","Error",@MB_OK|@MB_ICONEXCLAMATION)
return
endif

spcl = "x"
SELECT BSel
CASE 1
spcl = " "
CASE 2
spcl = "_"
CASE 3
spcl = "-"
CASE 4
spcl = sc
ENDSELECT

$IFDEF DEBUG
DEBUGPRINT "spcl=" + spcl
$ENDIF

max = -1

path += "\\"

temp = path + "*.*"

for i = 1 to td
f$ = ltrim$(str$(i))
if (len(f$) < 2) then f$ = "0" + f$
temp = path + "\\" + f$
f = CREATEDIR(temp)
if (f = 0) then
messagebox(d1,"Problem--Directory not created " + temp,"Error",@MB_OK|@MB_ICONEXCLAMATION)
Return
endif
next i

f = 1
f$ = "01"

/* Move files */
z = openfile(iFile,"C:\\!!ZZSORT.ZZZ","R")
$IFDEF DEBUG
DEBUGPRINT "z=" + str$(z)
$ENDIF
if (z = 0)
$IFDEF DEBUG
DEBUGPRINT "File Open"
$ENDIF
while (read(iFile,filename) = 0)
z = instr(filename, spcl)
if (z <> 0)
curr = left$(filename, z)
if (prev = "") then prev = curr
if (prev <> curr)
f++
if (f > td) then f = 1
f$ = ltrim$(str$(f))
if (len(f$) < 2) then f$ = "0" + f$
prev = curr
endif
npath = path + f$ + "\\"
res = RENAME(path + filename, npath + filename)
if (res)
Z = 1
else
messagebox(d1,filename + " Not MOVED " + path + " - " + npath,"Error",@MB_OK|@MB_ICONEXCLAMATION)
endif
endif
wend
closefile(iFile)
endif
return
endsub

'==============================================
SUB GetFolder(win:WINDOW, title:STRING), STRING
'==============================================
'open a folderrequest dialog
DEF path[260] AS ISTRING
DEF pszPath AS INT
DEF bi:BROWSEINFO
DEF lpIDList:INT
DEF Buffer:STRING

'initialize variables
path[0] = 0
RtlZeroMemory(bi,LEN(bi))
bi.hOwner = win.hwnd
bi.pszDisplayName = Buffer
bi.lpszTitle = title
bi.ulFlags = 0x00000001

'browse for folder
lpIDList = SHBrowseForFolder(bi)
IF lpIDList <> 0
pszPath = SHGetPathFromIDList(lpIDList,path)
CoTaskMemFree(lpIDList)
ENDIF
RETURN path
ENDSUB

I shouldn't have put the whole program here but at least you can look it over.
At any rate all the buttons are in order and it works. Also a little shorter. The button states aren't
checked and assignments not made until your ready to process.
There still seems to be a problem with edit_3 as it keeps exiting the program when you put a character in it, but that's a different issue I think.
Bill, feel free to use my changes if you want. Hope this helps.
Steve

billhsln

To gridt51, I used your solution and it seems to work exactly as what I am looking for.

My version is not exiting when some one enters something in Edit_3.  But, what it is doing is not 100% what I want it to.  Will keep playing.

Thanks for the help,
Bill
When all else fails, get a bigger hammer.

grid51

You are welcome Bill glad I could help.  Actually, what I did was pretty much what Larry suggested
in his first post 2nd suggestion on the checkstates. Sorry Larry, didn't look at that part too close.
You had the solution right there. I only took out the extra case statements.
Bill I don't know why it exits when I enter a char in Edit 3 and yours doesn't but I did try moving
the var assignments down below the checkstates and it seemed to work. May be something there.
Steve