Rodomi pranešimai su žymėmis VB. Rodyti visus pranešimus
Rodomi pranešimai su žymėmis VB. Rodyti visus pranešimus

2015 m. balandžio 10 d., penktadienis

2014 m. birželio 5 d., ketvirtadienis

Kaip įgyvendinti IComparer interfeisą su Visual Basic?

Problema: išrikiuoti Dictionary objektą.

Sprendimas:

1. Inicializuoti pradinius duomenis

        Dim Dictionary As New Dictionary(Of String, Integer)

        Dictionary.Add("A", 1)
        Dictionary.Add("B", 8)
        Dictionary.Add("C", 7)
        Dictionary.Add("D", 4)
        Dictionary.Add("E", 78)
        Dictionary.Add("F", 0)
        Dictionary.Add("G", 1)
        Dictionary.Add("H", 0)
        Dictionary.Add("I", 7)
        Dictionary.Add("J", 12)
        Dictionary.Add("K", 41)
        Dictionary.Add("L", 6)

2. Išrikiuoti

        Dictionary = SortDictionary(Dictionary)

3. Įgyvendinti SortDictionary funkciją

Private Function SortDictionary(ByVal dictionaryToSort As Dictionary(Of String, Integer)) As Dictionary(Of String, Integer)
        Dim SortList As List(Of KeyValuePair(Of String, Integer))
        SortList = dictionaryToSort.ToList
        dictionaryToSort.Clear()

        SortList.Sort(New DictionaryValueComparer)
        Return SortList.ToDictionary(Of String, Integer)(Function(keyPair As KeyValuePair(Of String, Integer)) keyPair.Key, Function(valuePair As KeyValuePair(Of String, Integer)) valuePair.Value)
    End Function

    Private Class DictionaryValueComparer
        Implements IComparer(Of KeyValuePair(Of String, Integer))
        Public Function Compare(ByVal x As System.Collections.Generic.KeyValuePair(Of String, Integer), ByVal y As System.Collections.Generic.KeyValuePair(Of String, Integer)) As Integer Implements System.Collections.Generic.IComparer(Of System.Collections.Generic.KeyValuePair(Of String, Integer)).Compare

            Dim num1 As Integer = x.Value
            Dim num2 As Integer = y.Value

            If num1 < num2 Then
                Return 1
            End If
            If num1 > num2 Then
                Return -1
            End If

            Return 0
        End Function
    End Class


Rezultatai:



http://stackoverflow.com/questions/2671236/sorting-a-dictionary-by-value - išrikiuoja skaičius
http://www.daniweb.com/software-development/vbnet/code/361733/sort-a-dictionary - išrikiuoja String eilutes

2014 m. balandžio 18 d., penktadienis

Visual Basic: Round su MidpointRounding.AwayFromZero

Decimal.Round((CDec(SkaiciusDecimal)), 0, MidpointRounding.AwayFromZero)

2014 m. kovo 6 d., ketvirtadienis

VB Page_Load įvykio vykdymas

 Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load, Me.Load

End Sub


Du kartus naudojamas MyBase.Load, Me. Load rodo, kad Page_Load įvykis bus vykdomas du kartus.

2014 m. sausio 8 d., trečiadienis

Attribute specifier is not a complete statement. Use a line continuation to apply the attribute to the following statement.

Problema:
 
·         CompilerServices.DesignerGenerated()> _
·         "font-size:9.16667px"><WebService(Namespace:="http://autogalleries.ca/")> _
·         =WsiProfiles.BasicProfile1_1)> _
·         ScriptService()> _
·         When I try to compile, it gives me the error: 
Error 1
Attribute specifier is not a complete statement. Use a line continuation to apply the attribute to the following statement.
 
 
Sprendimas:
 
_ turi būti dedamas vienu tarpu nuo eilutėje esančio teksto, pvz.,:
 
BLOGAI: CompilerServices.DesignerGenerated()>
GERAI: CompilerServices.DesignerGenerated()> _
 
 
Line continuation character '_' must be preceded by at least one white space and must be the last character on the line.
 

2013 m. spalio 10 d., ketvirtadienis

Function format file size

Public Shared Function FormatFileSize(ByVal FileSizeBytes As Long) As String
        Dim sizeTypes() As String = {"b", "Kb", "Mb", "Gb"}
        Dim Len As Decimal = FileSizeBytes
        Dim sizeType As Integer = 0
        Do While Len > 1024
            Len = Decimal.Round(Len / 1024, 2)
            sizeType += 1
            If sizeType >= sizeTypes.Length - 1 Then Exit Do
        Loop

        Dim Resp As String = Len.ToString & " " & sizeTypes(sizeType)
        Return Resp
    End Function

2013 m. spalio 7 d., pirmadienis

Tipų konvertavimas: ToBase64String

Modern applications increasingly use plain text to store and share data, especially in XML and SOAP formats. However, binary data cannot be represented directly in plain text, so one popular method is to convert binary to Base64 format.

What is Base64?

Base64 converts binary data to plain text using 64 case-sensitive, printable ASCII characters: A-Z, a-z, 0-9, plus sign (+) and forward slash (/), and may be terminated with 0-2 “padding” characters represented by the equal sign (=). For example, the eight-byte binary data in hex “35 71 4d 8e 4c 5f db 42″ converts to Base64 text as “NXFNjkxf20I=”.

.NET Convert Methods

Generally, to convert between Base64 and plain text, you should use the .NET methods Convert.ToBase64String and Convert.FromBase64String.

Custom Conversions


However, there may be instances when you want to modify the Base64 standard conversion behavior. For example, applications may use Base64 in file paths or URLs to represent globally unique IDs and other binary data. However, the forward slash is an invalid character in file paths. In URLs, the ‘+’ and ‘/’ characters translate into special percent-encoded hexadecimal sequences (‘+’ = ‘%2B’ and ‘/’ = ‘%2F’), and databases may choke on the % character because it represents a wildcard in ANSI SQL. Therefore, a modified “Base64 for URL” variant exists, where no ‘=’ padding is used, and the ‘+’ and ‘/’ characters are replaced with the hyphen ‘-’ and underscore ‘_’, respectively.


Function getBase64Text(ByVal sInput As String) As String
        Return System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(sInput))
    End Function

http://www.csharp411.com/convert-binary-to-base64-string/

2013 m. spalio 3 d., ketvirtadienis

Mod and division in Visual Basic

Dim hrs As Integer = allmins \ 60
Dim minutes As Integer = allmins Mod 60

Related operators include the following:

2013 m. rugsėjo 25 d., trečiadienis

AsyncPostBackTrigger nenaudoti su Response.Write

Dideliuose projektuose, kur daug JavaScript bibliotekų ir UpdatePanel, gaunama "mistinė" klaida dėl to, kad vb kode buvo panaudotas Response.Write

2013 m. rugsėjo 10 d., antradienis

CustomValidator pavyzdys su VB ASP.NET

Užduotis: jeigu CheckBox pažymėtas varnele, privaloma užpildyti dar du laukus: tbInfo ir tbInfo2


                             
ID="cvMeet" runat="server"
ErrorMessage="Privalomas"
OnServerValidate="cvMeet_ServerValidate"
ValidateEmptyText="True"
ClientValidationFunction="validateTaxiOrderForm" ForeColor="Red">


JavaScript:

function validateTaxiOrderForm ( source, args) {
            if ($("#cbMeet").val() == "checked"
                && $("#tbInfo").val() == ""
               && $.trim($("#tbInfo2").val()) == "") {

                args.IsValid = false;
            } else {
                args.IsValid = true;
                window.returnValue = true;
            };

        };

VB:
Protected Sub cvMeet_ServerValidate(source As Object, args As ServerValidateEventArgs) Handles cvMeet.ServerValidate
        If cbMeet.Checked = True Then
            Validate("meet")
            If Not IsValid Then
                Return
            End If
        End If
    End Sub

Client-side valdidavimą galima išjungti su savybe EnableClientScript=false

2013 m. rugpjūčio 23 d., penktadienis

Understanding RegisterClientScriptBlock and RegisterStartupScript

RegisterClientScriptBlock - įterpia javascript tekstą prieš formuojant HTML(nenaudojamas dirbant su UpdatePanel, nes scriptų neužregistruoja).

RegisterStartupScript - įterpia javascript tekstą jau suformavus HTML elementus (naudojama inicializacijai ir dirbant su UpdatePanel).

Partial Class Default2
    Inherits System.Web.UI.Page

    Protected Sub Page_PreRender(sender As Object, e As EventArgs) Handles Me.PreRender
        Dim sScript As String = "" &
            "function checkBox() {" &
            "   if (document.getElementById('" + TextBox1.ClientID + "').value != 'OK') {alert('Wrong'); return false} else {return true};" &
            "};"
        ScriptManager.RegisterClientScriptBlock(Me, Me.GetType, "tt", sScript, True)

        Button1.Attributes.Add("onclick", "return checkBox();") - užregistruoja, kada turi būti iškviečiama javascript funkcija

        ScriptManager.RegisterStartupScript(Me, Me.GetType(), "ttt", "document.getElementById('" + TextBox1.ClientID + "').value = '" & Now().ToString() & "';", True)
    End Sub

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Literal1.Text = Now()
    End Sub
End Class

Pagal tokį kodą, HTML suformuojamas taip:


2013 m. birželio 3 d., pirmadienis

LINQ property ReadOnly

Norint atnaujinti laukus, būtina išsiselectinti visą objektą, o ne kelias properties:

Dim objUsrThis = (From e In oDB.Employees Where e.Id = currEmpID).FirstOrDefault


objUsrThis.Login = txtLogin.Text.Trim

oDB.SubmitChanges()

2013 m. vasario 3 d., sekmadienis

How to add global.asax file

http://www.aspdotnet-suresh.com/2011/05/how-to-add-globalasaxcs-file-in-aspnet.html

Kaip nuskaityti XML dokumentą?


Dim oDoc As New XmlDocument()
oDoc.Load(fuXmlFile.FileName)

Dim pNum As String = oDoc.DocumentElement.GetElementsByTagName("title")(0).InnerText

Dim arMovies = oDoc.DocumentElement.GetElementsByTagName("movie")
For i As Integer = 0 To arMovies.Count - 1
    Dim oMovie = arMovies.Item(i)
    oMovie.Attributes.GetNamedItem("src").Value
Next

2013 m. sausio 10 d., ketvirtadienis

JavaScript IE vs JavaScript Chrome

IE works:

function validateMax2500Len(source, args) {


var x = (document.getElementById("txtDesc").value);

var l = document.getElementById("txtDesc").lastChild.length;

document.getElementById("lblLength").innerText = l;

if (x != "") {

if (l <= 100) { args.IsValid = true; }

else { args.IsValid = false; }

};

};   Chrome works:   function validateMax2500Len(source, args) {

var x = (document.getElementById("txtDesc").value);

var l = document.getElementById("txtDesc").value.length;

document.getElementById("lblLength").innerText = l;

if (x != "") {

if (l <= 100) { args.IsValid = true; }

else { args.IsValid = false; }

};

};

2012 m. spalio 15 d., pirmadienis

Kaip pakeisti linebreak TextBox MultiLine elemente į žymę < br / >?

Problema:

Dabar gaunu tekstą:

Tekstas: vienas du trys

Noriu gauti taip:

Tekstas:
vienas
du
trys

Sprendimas:

Pridėkite tokį kodą:


tbNotes.Text = tbNotes.Text.Replace(vbLf, "
"
+ vbCrLf)

tbNotes.Text = tbNotes.Text.Replace(vbCrLf, "
"
+ vbCrLf)

tbNotes.Text = tbNotes.Text.Replace(vbNewLine, "
"
+ vbCrLf)

http://stackoverflow.com/questions/9208822/how-can-i-change-the-linebreaks-from-a-multiline-textbox-to-html-br-tags


2012 m. rugpjūčio 7 d., antradienis

ShowModalDialog and cache

Puslapiuose, kurie iškviečiami naudojant showModalDialog, kaip čia:
varsFeatures = "dialogWidth:880px;dialogHeight:600px;status:no;unadorned:yes;help:no;";

var oResult = window.showModalDialog("Test.aspx?GroupID=" + courseID, null, sFeatures);

Būtinai užkraunant Test.aspx puslapyje Page_Load įvykyje reikia eilutės:

Response.Cache.SetNoStore()

2012 m. rugpjūčio 4 d., šeštadienis

Value of type '1-dimensional array of System.Data.DataRow' cannot be converted to 'System.Data.DataRow'.

Problema: Value of type '1-dimensional array of System.Data.DataRow' cannot be converted to 'System.Data.DataRow'.

The Select() method of the datatable returns a 1-dimensional array of type DataRow. The following example should give you a guide.

Dim rows() As DataRow

rows = DataSchema1.Clientes.Select("IdCliente = IdClienLabel.Text")


If (Not rows Is Nothing) Then

    Text1.Text = rows(0).Item("Nombre").ToString

End If

ASP.NET: kaip sukurti diagramą (angl. Chart)

  1. Apie visus diagramų tipus: http://blogs.msdn.com/b/alexgor/archive/2009/02/21/data-binding-ms-chart-control.aspx
  2.  Buvo gauta tokia klaida: Invalid temp directory in chart handler configuration [c:\TempImageFiles\]. Išsprendžiau taip: http://stackoverflow.com/questions/2660606/asp-netinvalid-temp-directory-in-chart-handler-configuration-c-tempimagefiles 
  3. Galutinis kodas: