September 21, 2020, 02:24:18 am

News:

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


Browsing for folders in console mode

Started by Egil, June 17, 2016, 10:51:29 am

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Egil

I promised to help a couple of young boys with a program that can communicate with an Arduino microcontroller. They already communicate with the controller via a serial port, using a character based console mode terminal program posted  on this forum some weeks ago.
Last night I was asked if I could add routines for downloading data from the microcontroller to a directory on the pc they can choose themselves.
Since I have never done this in console mode and was unable to find that any of the standard commands for this, I modified an example from the old IBA Std Archive (BrowseForFolder.iba), so it could be used in console mode.
The snippet works fine as long as AUTODEFINE is on. As soon as it is turned off, the program stops with an error message (see attached picture).

I have struggled for hours trying to understand why this happen, but so far with no luck. Maybe some of you can see what I am doing wrong?


Any suggestions are most welcome.

Egil


Code Select
'
' GetFolder.cba
'----------------------------------------------------------------------------------------

'autodefine "off"

CONST BIF_DONTGOBELOWDOMAIN = &H2
const BIF_RETURNONLYFSDIRS=&H1
const BIF_BROWSEFORCOMPUTERS=&H1000
const BIF_BROWSEFORPRINTERS=&H2000

def pidl:int
def buffer:string

Type BROWSEINFO
    def hWnd:int
    def root:int
    def folder:string
    def title:string
    def flags:int
    def callback:int
    def lparam:int
    def iimage:int
EndType

DECLARE "shell32",SHBrowseForFolder(lpbi:BROWSEINFO),int
declare "shell32",SHGetPathFromIDList(pidl:int,pszPath:string)
DECLARE "ole32",CoTaskMemFree(pidl:int)

DECLARE GETDIR()
def path:string

OPENCONSOLE

path = GETDIR()
print path

print:print
print "Press any key to exit"
do:until inkey$<>""
closeconsole
end


SUB GETDIR()
'----------------------------------------------------------------------------------------
def bi:BROWSEINFO
'bi.hWnd=win :' This line deleted in console mode
bi.root=0
bi.folder=buffer
bi.title="Choose a Folder.."
bi.flags=BIF_RETURNONLYFSDIRS

pidl=SHBrowseForFolder(bi)

if pidl<>0
SHGetPathFromIDList(pidl,buffer)
CoTaskMemFree(pidl)
endif

RETURN buffer



Support Amateur Radio  -  Have a ham  for dinner!

GWS

Hi Egil.

That one always catches me out as well ..  :)

All you need is to define the variable types before you set them as constants  ;D

def BIF_DONTGOBELOWDOMAIN, BIF_RETURNONLYFSDIRS:int
def BIF_BROWSEFORCOMPUTERS, BIF_BROWSEFORPRINTERS:int

const BIF_DONTGOBELOWDOMAIN = &H2
const BIF_RETURNONLYFSDIRS = &H1
const BIF_BROWSEFORCOMPUTERS = &H1000
const BIF_BROWSEFORPRINTERS = &H2000

Best wishes, :)

Graham
Tomorrow may be too late ..

Egil

Thanks Graham!

I never thought of that myself. But the truth is that whenever I have used such constants (not very often), I have never defined them in that way, and never got any error messages...
Works great now. Only thing left now is to modify the sub, so it can be used unmodified both in console mode and gui mode. Think that  sulution will be more obvious.

I hope these two boys learn english fast, as they do a lot of stuff with their robots. Right now they are making a weather station, and want to use CB to tailor the programs to their needs, so they can remote control the station. There is plenty of software available to help them do this, with instructions in norwegian. But they want to be in control of how the software behaves themselves, and feels the easiest way is to do it with CB.
Kind of like that attitude. :D


Regards,

Egil.
Support Amateur Radio  -  Have a ham  for dinner!

GWS

 ;D ;D .. nice to know today's young men appreciate how useful CB can be ..

all the best, :)

Graham
Tomorrow may be too late ..

Egil

The software bundled with the Arduino microcontroller and sensor boards, work ok for programming and controlling the boards. But it is in some situations very ackward to use.
So when I gave them a USB-stick with CB community version plus the serial comms routines, things became much easier. The "homebrew" comms routines did not chrash if they typed something wrong, and it became easier to experiment with the pc-side program. And that's the situation today, they even gave me a challenge I could not solve myself..... ;D


Regards,
Egil.
Support Amateur Radio  -  Have a ham  for dinner!