Imagen

Código: Seleccionar todo

' Gambas class file



PUBLIC SUB Form_Open()
DIM a AS Integer
vg.inicioaplicacion = 1 'primera ejecucion

 vg.colorlabel.Resize(10 + 1)

ME.center

'definimo los colores iniciales, que luego podremos cambiar haciendo doble clik en el label


a = 1
label1.BackColor = color.RGB(a * 100, a * 10, a * 50)
 vg.colorlabel[1] = color.RGB(a * 100, a * 10, a * 50)


a = a + 1
label2.BackColor = color.RGB(a * 100, a * 10, a * 50)
vg.colorlabel[2] = color.RGB(a * 100, a * 10, a * 50)

a = a + 1
label3.BackColor = color.RGB(a * 100, a * 10, a * 50)
vg.colorlabel[3] = color.RGB(a * 100, a * 10, a * 50)

a = a + 1
label4.BackColor = color.RGB(a * 100, a * 10, a * 50)
vg.colorlabel[4] = color.RGB(a * 100, a * 10, a * 50)

a = a + 1
label5.BackColor = color.RGB(a * 100, a * 10, a * 50)
vg.colorlabel[5] = color.RGB(a * 100, a * 10, a * 50)

a = a + 1
label6.BackColor = color.RGB(a * 100, a * 10, a * 50)
vg.colorlabel[6] = color.RGB(a * 100, a * 10, a * 50)

a = a + 1
label7.BackColor = color.RGB(a * 100, a * 10, a * 50)
vg.colorlabel[7] = color.RGB(a * 100, a * 10, a * 50)

a = a + 1
label8.BackColor = color.RGB(a * 100, a * 10, a * 50)
vg.colorlabel[8] = color.RGB(a * 100, a * 10, a * 50)

a = a + 1
label9.BackColor = color.RGB(a * 100, a * 10, a * 50)
vg.colorlabel[9] = color.RGB(a * 100, a * 10, a * 50)

a = a + 1
label10.BackColor = color.RGB(a * 100, a * 10, a * 50)
vg.colorlabel[10] = color.RGB(a * 100, a * 10, a * 50)

'defino cuantas variables hay 
vg.textoleyenda.Resize(11)
vg.valores.Resize(10 + 1)

label16.backcolor = color.RGB(223, 255, 255)


FMain.title = "Grafico Tarta: Ninguno"
DrawingArea1.Clear
Draw.Begin(DrawingArea1)
END




PUBLIC SUB ToolButton1_Click()
DIM dymax AS Integer
DIM dymin AS Integer 
DIM ymax AS Integer
DIM ymin AS Integer
DIM y AS Float
DIM dy AS Float
DIM dyi AS Integer
DIM dxmax AS Integer
DIM dxmin AS Integer 
DIM xmax AS Integer
DIM xmin AS Integer
DIM x AS Float
DIM dx AS Float
DIM dxi AS Integer
DIM k AS Float 
DIM a AS Float 
DIM w AS Float
DIM i AS Integer
DIM anguloinicio AS Float
DIM angulofin AS Float
DIM refy AS Integer
DIM cuadros AS Integer
DIM TextoEscribir AS String

recalcula()
dymax = DrawingArea1.Height
dymin = 0 
ymax = 2
ymin = -2
dxmax = DrawingArea1.Width
dxmin = 0 
xmax = 2
xmin = -2 

Draw.Begin(DrawingArea1)
' Draws a line horizontally across the centre of the form
'Draw.Line(0, DrawingArea1.Height / 2, DrawingArea1.Width, DrawingArea1.Height / 2)
' Draws a line vertically down the centre of the form
'Draw.Line(DrawingArea1.Width / 2, 0, DrawingArea1.Width / 2, DrawingArea1.Height)

DrawingArea1.Clear 'borra el area de dibuja cada vez que empecemos a dibujar algo.

Draw.fillstyle = Fill.Solid

anguloinicio = 0
cuadros = 0
FOR a = 1 TO 10
'100 es 360
angulofin = vg.valores[a - 1] * 360 
IF angulofin = 0 THEN GOTO findibujar
cuadros = cuadros + 1
Draw.FillColor = vg.colorlabel[a]
PRINT a, anguloinicio, angulofin

Draw.Circle(coorx(-100), coory(0), 100, angulo(anguloinicio), angulo(anguloinicio + angulofin))
anguloinicio = anguloinicio + angulofin


NEXT


findibujar:

 draw.ForeColor = color.black
Draw.Text(TextBox1.text, 150, 50, 1, 1, 3) 'centrado 3
'Draw.Text(TextBox1.text , 150, 25, 1, 1, 1) 'derecha 1
'Draw.Text(TextBox1.text , 150, 75, 1, 1, 2) 'izquierda 2
'Draw.Text(TextBox1.text , 150, 75, 1, 1, 4) 'cambio de alineacion

'dibujo leyenda

refy = DrawingArea1.Height / 2 - cuadros * 20 / 2

vg.textoleyenda[1] = textbox2.text
vg.textoleyenda[2] = textbox3.text
vg.textoleyenda[3] = textbox4.text
vg.textoleyenda[4] = textbox5.text
vg.textoleyenda[5] = textbox6.text
vg.textoleyenda[6] = textbox7.text
vg.textoleyenda[7] = textbox8.text
vg.textoleyenda[8] = textbox9.text
vg.textoleyenda[9] = textbox10.text
vg.textoleyenda[10] = textbox11.text


FOR a = 1 TO 10
draw.Text("Leyenda", 275, refy)
IF vg.valores[a - 1] = 0 THEN GOTO findibujarleyenda
Draw.FillColor = vg.colorlabel[a]
draw.Rect(250, 10 + a * 20 + refy, 10, 10)

TextoEscribir = vg.textoleyenda[a] & " (" & Format$(vg.valores[a - 1], " ###.## %") & ")"

draw.Text(TextoEscribir, 275, 15 + a * 20 + refy, 1, 1, 1)

NEXT 


findibujarleyenda:

Draw.End


fin:
END

PUBLIC SUB Button1_Click()

  Draw.End
  ME.Close

END


PUBLIC FUNCTION coorx(valor AS Float) AS Float
  
  RETURN DrawingArea1.Width / 2 + valor
  
  
END
PUBLIC FUNCTION coory(valor AS Float) AS Float
  
  RETURN DrawingArea1.Height / 2 + valor
  
  
END



PUBLIC FUNCTION angulo(valor AS Float) AS Float

'360 AS 2 x3, 14
RETURN (valor * 6.28 / 360)
  
END



'************************************************************
' introduciendo datos
'************************************************************


PUBLIC SUB ValueBox1_KeyPress()

  IF Key.code = Key.enter OR Key.code = Key.Return THEN 
        
         ToolButton1_Click
        textbox3.SetFocus
        END IF
END 

PUBLIC SUB ValueBox2_KeyPress()

    IF Key.code = Key.enter OR Key.code = Key.Return THEN 
       ToolButton1_Click
        textbox4.SetFocus
        END IF

END

PUBLIC SUB ValueBox3_KeyPress()

    IF Key.code = Key.enter OR Key.code = Key.Return THEN 
        ToolButton1_Click
        textbox5.SetFocus
        END IF

END

PUBLIC SUB ValueBox4_KeyPress()

    IF Key.code = Key.enter OR Key.code = Key.Return THEN 
         ToolButton1_Click
        textbox6.SetFocus
        END IF

END

PUBLIC SUB ValueBox5_KeyPress()

    IF Key.code = Key.enter OR Key.code = Key.Return THEN 
         ToolButton1_Click
        textbox7.SetFocus
        END IF

END

PUBLIC SUB ValueBox6_KeyPress()

    IF Key.code = Key.enter OR Key.code = Key.Return THEN 
        ToolButton1_Click
        textbox8.SetFocus
        END IF

END

PUBLIC SUB ValueBox7_KeyPress()

    IF Key.code = Key.enter OR Key.code = Key.Return THEN 
         ToolButton1_Click
        textbox9.SetFocus
        END IF

END

PUBLIC SUB ValueBox8_KeyPress()

    IF Key.code = Key.enter OR Key.code = Key.Return THEN 
         ToolButton1_Click
        textbox10.SetFocus
        END IF

END

PUBLIC SUB ValueBox9_KeyPress()

    IF Key.code = Key.enter OR Key.code = Key.Return THEN 
         ToolButton1_Click
        textbox11.SetFocus
        END IF

END

PUBLIC SUB ValueBox10_KeyPress()

    IF Key.code = Key.enter OR Key.code = Key.Return THEN 
        ToolButton1_Click
       textbox2.setfocus
       
        END IF

END

SUB recalcula()

  
  vg.suma = valuebox10.Value + valuebox9.value + valuebox8.Value + valuebox7.Value + valuebox6.Value + valuebox5.Value + valuebox4.Value + valuebox3.Value + valuebox2.Value + ValueBox1.Value
  IF vg.suma = 0 THEN 
     IF vg.inicioaplicacion = 1 THEN 
     GOTO finrecalcular
     ELSE 
      Message.Error("Debe de introducir algun dato")
      GOTO finrecalcular
      END IF
  END IF
  label1.text = Format$(valuebox1.value / vg.suma, "###.## %")
 vg.valores[0] = valuebox1.value / vg.suma
 
  
  label2.text = Format$(valuebox2.value / vg.suma, "###.## %")
  vg.valores[1] = valuebox2.value / vg.suma
  label3.text = Format$(valuebox3.value / vg.suma, "###.## %")
 vg.valores[2] = valuebox3.value / vg.suma
  label4.text = Format$(valuebox4.value / vg.suma, "###.## %")
  vg.valores[3] = valuebox4.value / vg.suma
  label5.text = Format$(valuebox5.value / vg.suma, "###.## %")
  vg.valores[4] = valuebox5.value / vg.suma
  label6.text = Format$(valuebox6.value / vg.suma, "###.## %")
  vg.valores[5] = valuebox6.value / vg.suma
  label7.text = Format$(valuebox7.value / vg.suma, "###.## %")
  vg.valores[6] = valuebox7.value / vg.suma
  label8.text = Format$(valuebox8.value / vg.suma, "###.## %")
  vg.valores[7] = valuebox8.value / vg.suma
  label9.text = Format$(valuebox9.value / vg.suma, "###.## %")
  vg.valores[8] = valuebox9.value / vg.suma
  label10.text = Format$(valuebox10.value / vg.suma, "###.## %")
  vg.valores[9] = valuebox10.value / vg.suma
  
  finrecalcular:
END


PUBLIC SUB Button2_Click()
DIM a AS Integer

  TextBox1.text = ""
  textbox2.Text = ""
   textbox3.Text = ""
   textbox4.Text = ""
   textbox5.Text = ""
   textbox6.Text = ""
   textbox7.Text = ""
   textbox8.Text = ""
  textbox9.Text = ""
  textbox10.Text = ""
  textbox11.Text = ""
  
  valuebox1.value = 0
  ValueBox2.value = 0
  valuebox3.value = 0
  valuebox4.value = 0
  valuebox5.value = 0
  valuebox6.value = 0
  valuebox7.value = 0
  valuebox8.value = 0
  valuebox9.value = 0
  valuebox10.value = 0
  
label1.text = 0
label2.text = 0
label3.text = 0
label4.text = 0
label5.text = 0
label6.text = 0
label7.text = 0
label8.text = 0
label9.text = 0
label10.text = 0
a = 1
label1.BackColor = color.RGB(a * 100, a * 10, a * 50)

 vg.colorlabel[1] = color.RGB(a * 100, a * 10, a * 50)


a = a + 1
label2.BackColor = color.RGB(a * 100, a * 10, a * 50)
vg.colorlabel[2] = color.RGB(a * 100, a * 10, a * 50)

a = a + 1
label3.BackColor = color.RGB(a * 100, a * 10, a * 50)
vg.colorlabel[3] = color.RGB(a * 100, a * 10, a * 50)

a = a + 1
label4.BackColor = color.RGB(a * 100, a * 10, a * 50)
vg.colorlabel[4] = color.RGB(a * 100, a * 10, a * 50)

a = a + 1
label5.BackColor = color.RGB(a * 100, a * 10, a * 50)
vg.colorlabel[5] = color.RGB(a * 100, a * 10, a * 50)

a = a + 1
label6.BackColor = color.RGB(a * 100, a * 10, a * 50)
vg.colorlabel[6] = color.RGB(a * 100, a * 10, a * 50)

a = a + 1
label7.BackColor = color.RGB(a * 100, a * 10, a * 50)
vg.colorlabel[7] = color.RGB(a * 100, a * 10, a * 50)

a = a + 1
label8.BackColor = color.RGB(a * 100, a * 10, a * 50)
vg.colorlabel[8] = color.RGB(a * 100, a * 10, a * 50)

a = a + 1
label9.BackColor = color.RGB(a * 100, a * 10, a * 50)
vg.colorlabel[9] = color.RGB(a * 100, a * 10, a * 50)

a = a + 1
label10.BackColor = color.RGB(a * 100, a * 10, a * 50)
vg.colorlabel[10] = color.RGB(a * 100, a * 10, a * 50)



DrawingArea1.Clear
  TextBox1.SetFocus

END


PUBLIC SUB Label1_DblClick()
 vg.colorbarra = label1.Background
  FmColor.ShowModal
  label1.Background = vg.colorbarra
  vg.colorlabel[1] = vg.colorbarra
ToolButton1_Click
END


PUBLIC SUB Label2_DblClick()
 vg.colorbarra = label2.Background
  FmColor.ShowModal
  label2.Background = vg.colorbarra
  vg.colorlabel[2] = vg.colorbarra
ToolButton1_Click
END

PUBLIC SUB Label3_DblClick()
 vg.colorbarra = label3.Background
  FmColor.ShowModal
  label3.Background = vg.colorbarra
  vg.colorlabel[3] = vg.colorbarra
ToolButton1_Click
END

PUBLIC SUB Label4_DblClick()
   vg.colorbarra = label4.Background
  FmColor.ShowModal
  label4.Background = vg.colorbarra
  vg.colorlabel[4] = vg.colorbarra
  ToolButton1_Click

END



PUBLIC SUB Label5_DblClick()
   vg.colorbarra = label5.Background
  FmColor.ShowModal
  label5.Background = vg.colorbarra
  vg.colorlabel[5] = vg.colorbarra
  ToolButton1_Click
END


PUBLIC SUB Label6_DblClick()
 vg.colorbarra = label6.Background
   FmColor.ShowModal
  label6.Background = vg.colorbarra
  vg.colorlabel[6] = vg.colorbarra
ToolButton1_Click
END


PUBLIC SUB Label7_DblClick()
 vg.colorbarra = label7.Background
    FmColor.ShowModal
  label7.Background = vg.colorbarra
  vg.colorlabel[7] = vg.colorbarra
ToolButton1_Click
END

PUBLIC SUB Label8_DblClick()
  vg.colorbarra = label8.Background
 FmColor.ShowModal
  label8.Background = vg.colorbarra
  vg.colorlabel[8] = vg.colorbarra
ToolButton1_Click
  

END

PUBLIC SUB Label9_DblClick()
 vg.colorbarra = label9.Background
  FmColor.ShowModal
  label9.Background = vg.colorbarra
  vg.colorlabel[9] = vg.colorbarra
ToolButton1_Click
END

PUBLIC SUB Label10_DblClick()
 vg.colorbarra = label10.Background
FmColor.ShowModal
  label10.Background = vg.colorbarra
  vg.colorlabel[10] = vg.colorbarra
  ToolButton1_Click
END




PUBLIC SUB TextBox2_KeyPress()

 IF Key.code = Key.enter OR Key.code = Key.Return THEN 
  vg.textoleyenda[1] = TextBox2.text
  ValueBox1.SetFocus
  END IF

END

PUBLIC SUB TextBox3_KeyPress()

 IF Key.code = Key.enter OR Key.code = Key.Return THEN 
  vg.textoleyenda[2] = TextBox3.text
  ValueBox2.SetFocus
  END IF

END


PUBLIC SUB TextBox4_KeyPress()

 IF Key.code = Key.enter OR Key.code = Key.Return THEN 
  vg.textoleyenda[3] = TextBox4.text
  ValueBox3.SetFocus
  END IF

END

PUBLIC SUB TextBox5_KeyPress()

 IF Key.code = Key.enter OR Key.code = Key.Return THEN 
  vg.textoleyenda[4] = TextBox5.text
  ValueBox4.SetFocus
  END IF

END

PUBLIC SUB TextBox6_KeyPress()

 IF Key.code = Key.enter OR Key.code = Key.Return THEN 
  vg.textoleyenda[5] = TextBox6.text
  ValueBox5.SetFocus
  END IF

END

PUBLIC SUB TextBox7_KeyPress()

 IF Key.code = Key.enter OR Key.code = Key.Return THEN 
  vg.textoleyenda[6] = TextBox7.text
  ValueBox6.SetFocus
  END IF

END

PUBLIC SUB TextBox8_KeyPress()

 IF Key.code = Key.enter OR Key.code = Key.Return THEN 
  vg.textoleyenda[7] = TextBox8.text
  ValueBox7.SetFocus
  END IF

END

PUBLIC SUB TextBox9_KeyPress()

 IF Key.code = Key.enter OR Key.code = Key.Return THEN 
  vg.textoleyenda[8] = TextBox9.text
  ValueBox8.SetFocus
  END IF

END

PUBLIC SUB TextBox10_KeyPress()

 IF Key.code = Key.enter OR Key.code = Key.Return THEN 
  vg.textoleyenda[9] = TextBox10.text
  ValueBox9.SetFocus
  END IF

END

PUBLIC SUB TextBox11_KeyPress()

 IF Key.code = Key.enter OR Key.code = Key.Return THEN 
  vg.textoleyenda[10] = TextBox11.text
  ValueBox10.SetFocus
  END IF

END


PUBLIC SUB TextBox1_KeyPress()

   IF Key.code = Key.enter OR Key.code = Key.Return THEN 
   textbox2.SetFocus
   END IF
   

END

PUBLIC SUB guardar_Click()
'tengo que guardar
'el titulo de diagrama
'los textos y valores

DIM lineas AS String
DIM destino AS String
DIM numArchivo AS Integer
DIM a AS Integer
    
    Dialog.Title = "Escriba  un nombre de archivo para guardar los datos"
   
    Dialog.Filter = ["*.diagrama", "Datos de diagrama"]
    
    IF NOT Dialog.SaveFile() THEN
        IF Right$(Dialog.Path, 9) <> ".diagrama" THEN
            destino = Dialog.Path & ".diagrama"
        ELSE
            destino = Dialog.Path
        END IF  
        FMain.title = "Grafico Tarta: " & Dialog.Path
        lineas = "************GRAFICO DE TARTA*************" & "\n"
        LINEas &= TextBox1.Text & "\n"
        
        'escribo texto de leyenda
        lineas &= "*************Textos de Leyenda ************" & "\n"
        FOR a = 1 TO 10
        LINEas &= CStr(vg.textoleyenda[a]) & "\n"
        NEXT 
        'escribo valores
        lineas &= "************* Valores ************" & "\n"
        'suma total
         LINEas &= CStr(vg.suma) & "\n"
        FOR a = 1 TO 10
        LINEas &= CStr(vg.valores[a - 1]) & "\n"
        NEXT 
        'escribo colores
        lineas &= "************* Colores ************" & "\n"
        FOR a = 1 TO 10
        lineas &= CStr(vg.colorlabel[a]) & "\n"
        NEXT 
        'final del fichero
        lineas &= "************* Fin ************" & "\n"
            File.Save(destino, lineas)
    END IF

  

END

PUBLIC SUB abrir_Click()

  DIM c AS String
  DIM arr_cadenas AS String[]
  DIM a AS Integer
  DIM b AS Integer
  
    Dialog.Title = "Seleccione un archivo"
     Dialog.Filter = ["*.diagrama", "Datos de diagrama"]
  
    IF NOT Dialog.OpenFile() THEN
        arr_cadenas = Split(File.LOAD(Dialog.Path), "\n")
          FMain.title = "Grafico Tarta: " & Dialog.Path
         ' lineas = "************GRAFICO DE TARTA*************"
        
         TextBox1.Text = arr_cadenas[1]
        
        b = 0
         
        FOR a = 2 TO 100
        IF arr_cadenas[a] = "************* Fin ************" THEN GOTO finLectura
      
        IF arr_cadenas[a] = "*************Textos de Leyenda ************" THEN 
             a = a + 1
             WHILE Mid$(arr_cadenas[a], 1, 3) <> "***"
             
              b = b + 1
                vg.textoleyenda[b] = arr_cadenas[a]
             a = a + 1 
             
              WEND 
              b = 0
              END IF
              
        'lectura de valores
        
        IF arr_cadenas[a] = "************* Valores ************" THEN 
             a = a + 1
             vg.suma = CFloat(arr_cadenas[a])
             a = a + 1
             WHILE Mid$(arr_cadenas[a], 1, 3) <> "***"
             
              b = b + 1
                vg.valores[b - 1] = CFloat(arr_cadenas[a])
             a = a + 1 
              WEND 
              b = 0
              END IF
        
        ' Lectura de colores
        IF arr_cadenas[a] = "************* Colores ************" THEN 
             a = a + 1
             WHILE Mid$(arr_cadenas[a], 1, 3) <> "***"
             
              b = b + 1
                vg.colorlabel[b] = CFloat(arr_cadenas[a]) 
             a = a + 1 
              WEND 
              a = a - 1
              END IF
        
        
        
        NEXT 
        
finlectura:
        

      textbox2.text = vg.textoleyenda[1]
      textbox3.text = vg.textoleyenda[2]
      textbox4.text = vg.textoleyenda[3]
      textbox5.text = vg.textoleyenda[4]
      textbox6.text = vg.textoleyenda[5]
      textbox7.text = vg.textoleyenda[6]
      textbox8.text = vg.textoleyenda[7]
      textbox9.text = vg.textoleyenda[8]
      textbox10.text = vg.textoleyenda[9]
      textbox11.text = vg.textoleyenda[10]

      ValueBox1.value = Int((vg.valores[0] * vg.suma) * 100) / 100
      ValueBox2.value = Int((vg.valores[1] * vg.suma) * 100) / 100
      ValueBox3.value = Int((vg.valores[2] * vg.suma) * 100) / 100
      ValueBox4.value = Int((vg.valores[03] * vg.suma) * 100) / 100
      ValueBox5.value = Int((vg.valores[04] * vg.suma) * 100) / 100
      ValueBox6.value = Int((vg.valores[05] * vg.suma) * 100) / 100
      ValueBox7.value = Int((vg.valores[06] * vg.suma) * 100) / 100
      ValueBox8.value = Int((vg.valores[07] * vg.suma) * 100) / 100
      ValueBox9.value = Int((vg.valores[08] * vg.suma) * 100) / 100
      ValueBox10.value = Int((vg.valores[09] * vg.suma) * 100) / 100
      
     
      
      
      

      label1.BackColor = vg.colorlabel[1]
      label2.BackColor = vg.colorlabel[2]
      label3.BackColor = vg.colorlabel[3]
      label4.BackColor = vg.colorlabel[4]
      label5.BackColor = vg.colorlabel[5]
      label6.BackColor = vg.colorlabel[6]
      label7.BackColor = vg.colorlabel[7]
      label8.BackColor = vg.colorlabel[8]
      label9.BackColor = vg.colorlabel[9]
      label10.BackColor = vg.colorlabel[10]
      
      
      ToolButton1_Click

    END IF


END





PUBLIC SUB DrawingArea1_Click()

  ToolButton1_Click

END



PUBLIC SUB DrawingArea1_Draw()

  ToolButton1_Click

END

PUBLIC SUB DrawingArea1_GotFocus()

  ToolButton1_Click

END

PUBLIC SUB Bguardarimagen_Click()
DIM destino AS String
DIM dibujo AS NEW Picture

  dibujo = DrawingArea1.Grab()
  
  Dialog.Title = "Escriba  un nombre de archivo para guardar la imagen"
   
    Dialog.Filter = ["*.BMP", "Datos en .BMP"]
    
    IF NOT Dialog.SaveFile() THEN
        IF Upper(Right$(Dialog.Path, 4)) <> ".BMP" THEN
            destino = Dialog.Path & ".BMP"
        ELSE
            destino = Dialog.Path
        END IF
  dibujo.Save(destino)
  
  END IF
  

END

PUBLIC SUB Label16_DblClick()
  vg.colorbarra = label16.Background
  FmColor.ShowModal
  label16.Background = vg.colorbarra
  DrawingArea1.Background = vg.colorbarra
ToolButton1_Click

END
Welcome to your nightmare, bitch.
Responder

Volver a “Otros lenguajes”