Tips&Tricks | I trucchi del mestiere |
![]() |
Bypassare la console di Windows |
//---Console "bypass" û E. Di Santo ---// //Queste istruzioni sono necessarie //per poter utilizzare la funzione "PlaySound" #include |
![]() |
Creazione di componenti a run-time |
Selected:=TToolButton(Sender).Tag; |
case Selected of 2: ControlRef:=TButton; 3: ControlRef:=TEdit; end; |
if Selected > 1 then with ControlRef.Create(Self) do begin Inc(Counter); Visible:=false; Parent:=Self; ControlName:=ControlRef.ClassName; Delete(ControlName,1,1); Name:=ControlName + IntToStr(Counter); Left:=X; Top:=Y; Visible:=true; tbNone.Down:=true; //tbNone = name del primo toolbutton tbNoneClick(tbNone); end; |
![]() |
Compilare le classi ôal voloö |
import java.io.*; import java.util.*; public class Compilertip { public static void main(String args[]) throws IOException { if(args.length==0){ System.out.println("Linea di comando: java Compilertip file1 file2 ecc"); }else{ Compile(args); } } /*Compila i file i cui nomi sono nel vettore fornito come parametro*/ static public boolean Compile(String[] filenames){ try{ int filecompilati = 0; for(int i=0;i<filenames.length;i++){ String fname = filenames[i]; String sourceFile = this.currentpath+""+fname[i]+".java"; int compileReturnCode = com.sun.tools.javac.Main.compile(new String[] {sourceFile}); if (compileReturnCode == 0) { System.out.println("File "+ filenames[i] + " compilato con successo."); filecompilati++; }else{ System.out.println("Errore nella compilazione di "+ filenames[i] + ". Termino."); return false; } }//for if(filecompilati == filenames.length){ System.out.println("Tutti i file ("+filecompilati+") compilati con successo."); return true; } catch(Exception e){ /*... gestione dell' errore...*/ } return false; } } /* javac -classpath c:\j2sdk1.4.2\lib\tools.jar Compilertip.java java -classpath c:\j2sdk1.4.2\lib\tools.jar Compilertip.java */ |
![]() |
Input bufferizzato |
package it.kya.io; import java.io.IOException; public class KeyBoard { static { System.loadLibrary("KeyBoard"); } public static native int read() throws IOException; } |
|
|
/* DO NOT EDIT THIS FILE - it is machine generated */ #include |
![]() |
La convalida della partita IVA |
boolean checkValidPartitaIva(String PartitaIva) { int Somma01 = 0; int Somma02 = 0; int CheckNumber; if (PartitaIva.length() != 11) return false; try { if(Float.parseFloat(PartitaIva) < Float.parseFloat("0")) return false; } catch (NumberFormatException NFE) {NFE.printStackTrace(); return false;} for (int i = 0; i < 9; i += 2) { CheckNumber = Integer.parseInt(""+PartitaIva.charAt(i)); Somma01 += CheckNumber; CheckNumber = Integer.parseInt(""+PartitaIva.charAt(i+1)); Somma01 += Math.floor(CheckNumber/5) + (CheckNumber << 1) % 10; } Somma02 = 10 - (Somma01 % 10); CheckNumber = Integer.parseInt(""+PartitaIva.charAt(10)); if (Somma02 != CheckNumber) return false; else return true; } |
![]() |
Gli utenti cambiano la dimensione dei controlli |
Private Declare Function ReleaseCapture Lib _ "user32" () As Long Private Declare Function SendMessage Lib _ "user32" Alias "SendMessageA" (ByVal hWnd _ As Long, ByVal wMsg As Long, ByVal wParam _ As Long, lParam As Any) As Long Private Const WM_NCLBUTTONDOWN = &HA1 Private Const HTLEFT = 10 Private Const HTRIGHT = 11 Private Sub Picture1_MouseDown(Button As _ Integer, Shift As Integer, X As Single, Y As Single) Dim nParam As Long With Picture1 ' You can change these coordinates to whatever ' you want If (X > 0 And X < 100) Then nParam = HTLEFT ElseIf (X > .Width - 100 And X < .Width) Then ' these too nParam = HTRIGHT End If If nParam Then Call ReleaseCapture Call SendMessage(.hWnd, _ WM_NCLBUTTONDOWN, nParam, 0) End If End With End Sub Private Sub Picture1_MouseMove(Button As _ Integer, Shift As Integer, X As Single, Y As Single) Dim NewPointer As MousePointerConstants ' You can change these coordinates to whatever you want If (X > 0 And X < 100) Then NewPointer = vbSizeWE ElseIf (X > Picture1.Width - 100 And X < _ Picture1.Width) Then ' these too NewPointer = vbSizeWE Else NewPointer = vbDefault End If If NewPointer <> Picture1.MousePointer Then Picture1.MousePointer = NewPointer End If End Sub |
![]() |
Leggere e scrivere in un file .INI |
Declare Function WritePrivateProfileString Lib "Kernel32" Alias "WritePrivateProfileStringA" ByVal lpApplicationname As String, ByVal lpKeyName As Any, ByVal lsString As Any, ByVal lplFilename As String) As Long Declare Function GetPrivateProfileInt Lib "Kernel32" Alias "GetPriviteProfileIntA" (ByVal lpApplicationname As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) As Long Declare Function GetPrivateProfileString Lib "Kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationname As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long Global File Global appname Global Keyname Global Value Public Function Store(File As String, Heading As String, Section As String, Value As String) Dim lpAppName As String, lpFileName As String, lpKeyName As String, lpString As String Dim U As Long lpAppName = Heading lpKeyName = Section lpString = Value lpFileName = File U = WritePrivateProfileString(lpAppName, lpKeyName, lpString, lpFileName) If U = 0 Then Beep Else Store = "Success" End If End Function Public Function GetValue(File As String, Heading As String, Section As String) Dim x As Long Dim Temp As String * 50 Dim lpAppName As String, lpKeyName As String, lpDefault As String, lpFileName As String Temp = Space$(50) lpAppName = Heading lpKeyName = Section lpDefault = no lpFileName = File x = GetPrivateProfileString(lpAppName, lpKeyName, lpDefault, Temp, Len(Temp), lpFileName) If x = 0 Then Beep Else en = InStr(1, Temp, Chr$(0)) If en > 0 Then Temp = Mid$(Temp, 1, en - 1) GetValue = Trim$(Temp) End If End Function |
![]() |
Un controllo ListView in modalitα ôreportö |
![]() |
Un risolutore dÆespressioni matematiche |