Simple and fast as ABC.
2011-10-22
Point density.
The most simple way how to calculate point density using Quantum GIS.
Simple and fast as ABC.
The text used in the clip can be found in the youtube as a video description.
Simple and fast as ABC.
2011-09-30
Assing an array as object property in Visual Basic 2010
I am not yet completely sure about how correctly this is, but it took a lot of time for me figuring out how to assign an array as a property.
I found out that firstly I had to define an array variable inside a class
Then I have to make a property, which returns element of the array
And finally I have to assign the values to an array inside a function or sub
I found out that firstly I had to define an array variable inside a class
Private temperatureArray() As Double
Then I have to make a property, which returns element of the array
Public ReadOnly Property temperatureVal(ByVal index As Integer) As Double
Get
Return temperatureArray(index)
End Get
End Property
And finally I have to assign the values to an array inside a function or sub
Sub getTemp()
ReDim tempVal(UBound(valuesArray)) 'valuesArray is some predefined array.
For i = 0 To UBound(valuesArray)
temperatureVal(i) = valuesArray(i)
Next i
End Sub
Simple textfield validating in Visual basic 2010
Simple way how to validate text fields.
If you have text field and you are using "_textChanged do something", then you probably know that it could be not enough. Depending on different specifications (usually such input is for numbers) and writing bad data like characters where should be numbers, it can make errors.
From my little experience, VB and similar program code is working based on "on error do something else".
In the following example I`m doing two things.
In the first I`m validating each keypress allowing just numbers, comma and decimal seperator,
And in the second - catching empty-string error. If someone deletes all content in the textbox, text is changed and passed string is empty, which does no good.
If you have text field and you are using "_textChanged do something", then you probably know that it could be not enough. Depending on different specifications (usually such input is for numbers) and writing bad data like characters where should be numbers, it can make errors.
From my little experience, VB and similar program code is working based on "on error do something else".
In the following example I`m doing two things.
In the first I`m validating each keypress allowing just numbers, comma and decimal seperator,
Private Sub step1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles step1.KeyPress
If (Not Char.IsNumber(e.KeyChar) AndAlso Not ".,-".Contains(e.KeyChar) AndAlso Not e.KeyChar = Microsoft.VisualBasic.Chr(Keys.Back)) Then
e.Handled = True
End If
End Sub
And in the second - catching empty-string error. If someone deletes all content in the textbox, text is changed and passed string is empty, which does no good.
Private Sub step1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles step1.TextChanged
On Error GoTo 11
If Not (step1.Text = String.Empty) Then
parametrs.setStep() 'this pass error
End If
11:
End Sub
2011-09-19
2011-09-17
First/last day of the month
2011.09.17.
Is the given date the first day of the month? Or maybe the last? Whatta silly question... of course not the first or last one! But sometimes it is useful to know or.. better let`s say, return "true" on that kind of questions.
I found that it could be done very easily with creating object from such string, returning parts, making new date value and done some comparing.
Ok, here are the steps-
and now - if we need to know is the date is the last day in the month.
See the changes?
Is the given date the first day of the month? Or maybe the last? Whatta silly question... of course not the first or last one! But sometimes it is useful to know or.. better let`s say, return "true" on that kind of questions.
I found that it could be done very easily with creating object from such string, returning parts, making new date value and done some comparing.
Ok, here are the steps-
$dateObj= new DateTime($datestring);
$currentDay=(int) $dateObj->format('d'); //make int not string. let`s get necessary date parts
$currentMonth=(int) $firstDate->format('m');
$currentYear=(int) $firstDate->format('y');
//let`s create another month value returning from the new date, where it is created from the day //before current date
$prevMonth = (int) date("m", mktime(0, 0, 0, $currentMonth, $currentDay-1, $currentYear));
//and finally - comparison
if ($currentMonth>$prevMonth)
{
return "true"; //if previous date is in the previous month, we have the first day of the month
//from date object parts you can make new date here based on your needs through mktime.
}
else
{
return "false";
}
and now - if we need to know is the date is the last day in the month.
$nextMonth = (int) date("m", mktime(0, 0, 0, $currentMonth, $currentDay+1, $currentYear));
if ($currentMonth<$nextMonth)
See the changes?
Avoiding injections
Very fast and useful way, how to avoid different injections in websites - if you know what type of variable can be.
For example - if you have any ID`s or other values which can be only integers - in the script you can always be sure that after such validation it will always be an integer just writing (int) before the variable - like -
For example - if you have any ID`s or other values which can be only integers - in the script you can always be sure that after such validation it will always be an integer just writing (int) before the variable - like -
$variable = (int) $_GET['variable'];Another example - if you have variable which could always be date - you could pass it as a string and build a date object from it
$date=$_GET['date'];Dealing with the float type it is very similar like integer type. But it is always necessary to remember - what is the decimal seperator of the host and decimal seperator in your country. In my case, I have to remember, that the host`s decimal seperator is dot, but usually people in Latvia are using comma. So, I have to parse the given "float string", and replace comma with dot, if there`s any.
$dateObj = new DateTime($date);
//if you need to get back to string in any case
$dateString = $date->format("Y-m-d") //or other format
$value=(float)str_replace(",",".",$value);
Abonēt:
Ziņas (Atom)