Small Basic: Propiedades y operaciones del objeto File


directorios

Usar propiedades del objeto File.

  • LastError

Usar operaciones del objeto File.

  • CreateDirectory
  • GetDirectories (obtener directorios)

Cree un directorio de acuerdo con un nombre introducido por el usuario.

Descargue un archivo de la red y lo copie en el directorio que ha creado.

Muestre el contenido del archivo descargado en la ventana de texto.

Acepte contenido adicional del usuario y agregue ese contenido al archivo.

Muestre el contenido final del archivo en la ventana de texto.

 

 

 

Nota: El archivo tiene que existir en la ruta de red especificada para que la solución funcione.

 

Solución:

TextWindow.Write(«Escriba el nombre del nuevo directorio: «)

NombreDirectorio = TextWindow.Read()

File.CreateDirectory(NombreDirectorio)

rutaarchivo = «\\mum-9785sm\Compartido\ArchivoEntradaSalidaO.txt»

rutadescarga = Network.DownloadFile(rutaarchivo)

If File.CopyFile(rutadescarga, NombreDirectorio) = «SUCCESS» Then

TextWindow.WriteLine(«El archivo ha sido descargado de la red y copiado a: » + NombreDirectorio )

archivos= File.GetFiles(NombreDirectorio)

TextWindow.WriteLine(«Este es el contenido del archivo: «)

TextWindow.WriteLine(File.ReadContents(archivos[1]))

TextWindow.Write(«Escriba los datos para agregarlos en el archivo: «)

DatosAgregados = TextWindow.Read()

File.AppendContents(archivos[1],» » + DatosAgregados)

TextWindow.WriteLine(«El contenido del archivo después de agregar los datos es como sigue: «)

TextWindow.WriteLine(File.ReadContents(archivos[1]))

EndIf

Small Basic: Intermediate Challenge 1 (Sushi restaurant)


sushiNao

Program Listing:    JWF370    http://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/bce001cb-ce65-4d23-8645-466098928115/

Intermediate Challenge 1

Write a program to display a menu that a till operator might use in a restaurant.  They click on the items the customer wants and it works out the bill.

………………………………………………………………………………………………………………………….

Code:

‘  Challenge of the month  May 2013     Restaurant  menu order   by  NaochanON

 

InitData()

GUI()

Controls.ButtonClicked=EnterData

Sub EnterData

btnnmb=Controls.LastClickedButton

nm=controls.GetButtonCaption(btnnmb)

if text.IsSubText(Btns,nm) Then  ‘

DNMB= Text.GetSubTextToEnd(btnnmb,7)                     ‘

Newconts= Menu[DNMB]

NewPrice= Price[DNMB]

DataEnter()

elseif  text.IsSubText(Newconts,nm) then

searchNo()

NN=NN+1

Order=order+NN+»: «+nm+»    «+Price[DNMB][PNMB]+CRLF

TotPrice=TotPrice+Price[DNMB][PNMB]

Mes=Order+CRLF+»   Price      = «+Totprice+CRLF

tax=math.floor(5*Totprice)/100

Mes=Mes+»   Tax(5%) = «+tax+CRLF

Mes=Mes+»   Total      = «+(Totprice+tax)+CRLF+CRLF+»   Thank you !»

Controls.SetTextBoxText(receipt,Mes)

EndIf

endsub

sub searchNo

For j=1 To Array.GetItemCount(Newconts)

If nm= Newconts[j] Then

PNMB=j

j=Array.GetItemCount(Newconts)

endif

EndFor

EndSub

Sub DataEnter

If NMB2<>0 Then

For j=1 To NMB2

Controls.HideControl(btn2[j])                  ‘

Controls.HideControl(btn3[j])

EndFor

EndIf

Shapes.Move(redrect,10,130+75*(DNMB-1))                            ‘  Red mark

‘————————————————————————————————————————-

NMB=Array.GetItemCount(Newconts)

GRXY=»W=500;H=»+(NMB*45)

GrayBox()

‘————————————————————————————————————————-

GraphicsWindow.BrushColor=»Navy»

For i=1 To NMB

btn2[i]=Controls.AddButton(Newconts[i],440,135+40*(i-1))         ‘  menu

btn3[i]=Controls.AddButton(«US$ «+NewPrice[i],760,135+40*(i-1))  ‘  price

Controls.SetSize(btn2[i],280,35)

Controls.SetSize(btn3[i],120,35)

EndFor

‘————————————————————————————————————————-

NMB2=NMB                                               ‘

endsub

Sub GrayBox

Shapes.Remove(GRBOX)

GraphicsWindow.BrushColor=»Lightgray»

GRBOX=Shapes.AddRectangle(GRXY[«W»],GRXY[«H»])           ‘  gray  box

Shapes.Move(GRBOX,400,120)

Shapes.SetOpacity(GRBOX,60)

EndSub

Sub GUI

GraphicsWindow.Width=Desktop.Width

GraphicsWindow.Height=Desktop.Height

GraphicsWindow.Top=0

GraphicsWindow.Left=0

GraphicsWindow.FontName=»Gergia»

GraphicsWindow.FontItalic=»true»

GraphicsWindow.DrawImage(back,0,0)                       ‘  background image

‘————————————————————————————————————————-

photo=Shapes.AddImage(Img)                               ‘  Sushi photo

Shapes.Zoom(photo,550/imgw,350/imgh)

Shapes.Move(photo,400,380)

Shapes.SetOpacity(photo,60)

‘————————————————————————————————————————-

GraphicsWindow.penColor=»Red»

GraphicsWindow.BrushColor=»Red»

redrect= Shapes.AddRectangle(30,30)

Shapes.Move(redrect,10,-100)

GraphicsWindow.FontSize=25

TTL=Shapes.AddText(» Sushi Restaurent  Order System  «)  ‘  Title

Shapes.Move(TTL,500,10)

‘————————————————————————————————————————-

GraphicsWindow.FontSize=25

GraphicsWindow.BrushColor=»Navy»

For i=1 To array.GetItemCount(Btns)

btn[i]= Controls.AddButton(Btns[i],50,125+75*(i-1))    ‘   Menu

Controls.SetSize(btn[i],250,55)

EndFor

‘————————————————————————————————————————-

GraphicsWindow.FontSize=16

receipt=Controls.AddMultiLineTextBox(1000,125)           ‘   receipt box

Controls.SetSize(receipt,350,600)

Shapes.SetOpacity(receipt,70)

EndSub

Sub InitData

back=ImageList.LoadImage(«C:\Windows\Web\Wallpaper\Scenes\img29.jpg»)

url= «http://farm7.static.flickr.com/6109/6245861119_1f06dabea8.jpg»

‘url=Flickr.GetRandomPicture(«Sushi»)

img= imagelist.LoadImage(url)

imgw= ImageList.GetWidthOfImage(img)

imgh= ImageList.GetHeightOfImage(img)

Btns=»1=Hot Appetizer;2=Cold Appetizer;3=Nigiri;4=Special Rolls;5=Sea Food;6=Dinner;7=Deserts&Beverage »

‘————————————————————————————————————————-

Menu[1]=»1=Japanese Eggplant;2=Tempura;3=Softshell Crab;4=Crab Cake;5=Oyster Saute»

Menu[2]=»1=Crab and Shrimp Sunomono;2=Aji tako Salad;3=Salmon radish Roll;4=Tuna with rice Biscuit»

Menu[3]=»1=Crab;2=Eel Sea;3=Halibut;4=Mackerel;5=Octopus;6=Omelet;7=Salmon;8=Salmon Roe;9=Scallop;10=Sea Urchin;11=Squid;12=Tuna»

Menu[4]=»1=Alaskan Roll;2=Hawaian Roll;3=Mexican Roll;4=Eel Roll;5=Avocado Roll»

Menu[5]=»1=Salmon;2=Scallops;3=Sea Bass;4=Tuna;5=Monk Fish;6=Black Cod;7=Yellow tail»

Menu[6]=»1=Chicken Teriyaki;2=Assorted Tempura;3=Sushi Deluxe;4=Assorted Sashimi Plate;5=Chirashi Sushi»

Menu[7]=»1=Ice Cream;2=Soda;3=Cola;4=Hot Tea;5=Cold Tea»

‘————————————————————————————————————————-

Price[1]=»1=7.00;2=7.00;3=8.50;4=9.50;5=7.00″

Price[2]=»1=7.00;2=9.50;3=9.50;4=10.50″

Price[3]=»1=3.50;2=5.00;3=4.50;4=3.50;5=4.00;6=3.00;7=4.00;8=5.00;9=4.50;10=7.50;11=3.75;12=4.50″

Price[4]=»1=12.00;2=12.50;3=11.50;4=10.50;5=7.50″

Price[5]=»1=12.00;2=14.00;3=16.50;4=15.50;5=13.00;6=13.50;7=14.50″

Price[6]=»1=12.00;2=13.00;3=22.00;4=24.50;5=22.50″

Price[7]=»1=2.50;2=1.50;3=1.50;4=2.00;5=1.50″

CRLF= Text.GetCharacter(13)+Text.GetCharacter(10)

EndSub