Affichage des articles dont le libellé est Active questions tagged vb.net - Stack Overflow. Afficher tous les articles
Affichage des articles dont le libellé est Active questions tagged vb.net - Stack Overflow. Afficher tous les articles

mercredi 6 mai 2015

How do I 'watch' list box selection change?

In WPF VB.NET 4.0, I have a list box that is populated with a data binding from XML. How can I set a live watch event to the listbox so that the selected item, based on a certain criteria (field is true or false), a button on the form has it's content changed to read something else?

i.e., user selects an item with XML element 'status' is set to 'current', then button would read, Finished. If user selects an item with XML element 'status' is set to 'finished', then button would read, Unfinished.

Continous Counting of Present Days

I want to count continuously 10 days attendance where attendance_ status is present and shift is III . I have table in sql database named as Attendance_Master having fields Emp_Code,Attendance_Date,Shift,Attendance_Status(for storing Present ,Absent Status). I am using VB.Net 2008 for coding. How could I do this?

Set HTML attribute dynamically

I'm trying to generate HTML dynamically, in a way that looks a bit like MVC. However I'm trying to achieve this in Webforms.

I managed to pass a list to my aspx page, but using the properties in the html attributes doesn't seem to work:

My aspx page:

<% For Each question As WorkOrderQuestionDAO In Session("WorkOrderQuestions") %>
    <tr>
        <td style="width: 620px"><%= question.Question %></td>
        <td style="width: 300px">
        <% Select Case question.WorkOrderAnswerTypeID
            Case 1 %>
                <asp:RadioButtonList ID='<%# question.QuestionID %>' runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow">
                    <asp:ListItem Value="-1">YES</asp:ListItem>
                    <asp:ListItem Value="0">NO</asp:ListItem>
                </asp:RadioButtonList>
            <%Exit Select
            Case 2 %>
                <asp:RadioButtonList ID='<%# question.QuestionID %>' runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow">
                    <asp:ListItem Value="-1">YES</asp:ListItem>
                    <asp:ListItem Value="0">NO</asp:ListItem>
                    <asp:ListItem Value="1">NA</asp:ListItem>
                </asp:RadioButtonList>
            <% Exit Select
        End Select%>
     </td>
  </tr>
<% Next %>

So I try to set the ID of each RadioButtonList automatically, by trying to insert the question.QuestionID property. However the error i'm getting is:

The ID property of a control can only be set using the ID attribute in the tag and a simple value. Example:

I tried:

ID='<%# question.QuestionID %>'
ID='<%= question.QuestionID %>'
ID='<%= Eval("question.QuestionID") %>'

At this point I don't know what syntax to use. I don't think it should be to hard, but I couldn't find an answer using Google and find it hard to come up with the proper search terms.

The <tr>, <td> and <asp:RadioButtonList> generation goes fine by the way.

Consolidate excel data in vb.net

I get an error on consolidate data using vb.net. Please help.

Imports Microsoft.Office.Interop

Public Class Form1 Dim xlsWorkSheet As Excel.Worksheet

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim xlsApp As New Excel.Application
    xlsApp.Visible = True
    Dim xlsWorkbook As Excel.Workbook = xlsApp.Workbooks.Open("C:\Users\hwai\Desktop\Consolidate.xlsx")

    xlsWorkSheet.Range("H1").Select().Consolidate("'C:\Users\hwai\Desktop\[Consolidate.xlsx]Sheet1'!A1:B8", _Function:=-4112, TopRow:=False, LeftColumn:=True, CreateLinks:=False)


End Sub

Thanks

Is it possible to Create trello.com like boards and cards using VB.net?

Hello programmers, Am new to VB.net and i have taken up a task of creating Exactly like TRELLO.com Using VB.net. Is there any possibilities of doing it?

This Should be the first WINFORM i Just Need the BOARDS and BOARDS Creation This Should be the first WINFORM i Just Need the BOARDS and BOARDS Creation

And when the Board has been Clicked Then it should give a new form like this with cards in it. LIKE IN THE RELEASE EVENT THERE ARE SEVERAL CARDS

And when the Board has been Clicked Then it should give a new form like this with cards in it. LIKE IN THE RELEASE EVENT THERE ARE SEVERAL CARDS

Now when you click on the card it should give you options like in the picture. Like Add Members for the Project, Adding Comment,Adding Objectives like in the image

Now when you click on the card it should give you options like in the picture. Like Add Members for the Project, Adding Comment,Adding Objectives like in the image

Now my Question Is whether it is possible to be creating Boards and Cards exectly are closely like trello.com using VB.net

If so then i will start Doing this Project. Please Help Me. Thanks in Advance

Select from sql in vb and display in aspx page

Just wanna select a word from database and display in aspx page

Backend

Using da As New SqlDataAdapter
        con.Open()
        cmd.CommandText = "SELECT value_en as value FROM tbl_language WHERE element_id = 'a1';"
        da.SelectCommand = cmd
        Dim dt As New DataTable
        da.Fill(dt)
        Dim WordValue As String = dt.Rows(0).Item(0)
End Using

in aspx page

<%=WordValue%>

whats wrong here?

Dynamically add code at runtime in VB(.NET)

I want to make a program in VB(.NET) in which per click on a button one or more new buttons are added to the UserForm. This process should work for an infinite number of times. Then the buttons shall call a public sub, handing over an individual variable so that the code knows what button it was called from (thus: knows what to do).

I learned how to create buttons at runtime with the Button = new Button and controls.add(Button) code. I also managed to pass a new code to the button by using WithEvents or an AddHandler. But until now I always need to have the code ready before the program is run. I.e. I need to know the name of the button in advance and have the code prepared.

Is there a way to dynamically create a code snipped at run time that will point to a pre-existing one?

I'll give you a simplyfied example:

WithEvents NewButton01 As New Button
WithEvents NewButton02 As New Button
WithEvents NewButton03 As New Button

Private Sub AddNewButton_Click() Handles AddNewButton.Click

    NewButton01.Location = New Point(10, 10)
    NewButton01.Text = "01"
    Controls.Add(NewButton01)

    NewButton02.Location = New Point(50, 50)
    NewButton02.Text = "02"
    Controls.Add(NewButton02)

    NewButton03.Location = New Point(90, 90)
    NewButton03.Text = "03"
    Controls.Add(NewButton03)

End Sub

Private Sub NewButton01_click() Handles NewButton01.Click
    Call MessageBox(1)
End Sub

Private Sub NewButton02_click() Handles NewButton02.Click
    Call MessageBox(2)
End Sub

Private Sub NewButton03_click() Handles NewButton03.Click
    Call MessageBox(3)
End Sub

Private Sub MessageBox(flag As Integer)
    MsgBox("You activated button number " & flag)
End Sub

As you can see, this is a very unprofessional way of coding. Also, I'd like to keep the amount of buttons created infinite, so I can't use this code. I'd rather have VB make a new button each time I click on "AddNewButton" and write a code that refers to Private Sub MessageBox or whatever code it may be in the end.

I am very new to VB.Net, so please forgive me if the examples contains anything that makes you shiver.

And thank you very much!

Best practises: Execute Javascript code on VBNET

I know that similar questions had been answered before on this forum. But none of them are what i was looking for.

I'm developing a desktop application to show, in the same place, at the same time, information of various web pages using web scraping. I'm having a lot of troubles to show information extracted of one of them.

I need to simulate a login on that page, the problem is that to simulate the POST message i have to cipher the password before do it. For example, when the user opens the page with the browser, he can write the password: "123456". When the user clicks "login", the content of the input is changed (cipher) by javascript before submitting the form.

Thats the behaviour I need to emulate. I know the login and the password of my user. However I need to cipher it before i can do the POST. I have the js file which do the cipher and i know what function i have to call.

I have developed a workaround, but it has not good execution time (Getting an aspx from my server, passing the password as an url parameter. This aspx executes the function on the onload event, and shows the result on the body).

I think there has to be a way to convert the js file to a dll file, to load it as a normal reference, allowing me to call the function directly on my winform application.

Image name rewrites the old one VB.NET - How to rename same image to a different name every time when upload the file?

I know how to rename a file, but, in this case i have a tool to upload one by one, a lot of images, and, when you try to upload two different images with the same name rewrites the old one.

I need to generate dinamically something to identify every upload as unique, but i dont know how to put a count++ in Vb.net,

thank you very much for your time and consideration.

Dim Upload2 As UploadDetail = DirectCast(Me.Session("UploadDetail"), UploadDetail)

Upload2.IsReady = False
        If fileUpload1.PostedFile IsNot Nothing AndAlso fileUpload1.PostedFile.ContentLength > 0 Then

Dim path__1 As String = UPLOADFOLDER & "/"
Dim fileOK As Boolean = False
Dim fileName As String = Path.GetFileName(fileUpload1.PostedFile.FileName)
Dim strPath As String = Path.Combine(path__1, fileName)

If fileUpload1.HasFile Then

Dim fileExtension As String
fileExtension = System.IO.Path. _
                    GetExtension(fileUpload1.FileName).ToLower()

Dim allowedExtensions As String() = _
{".jpg", ".jpeg", ".png", ".gif"}
                For i As Integer = 0 To allowedExtensions.Length - 1
                    If fileExtension = allowedExtensions(i) Then
                        fileOK = True
                    End If
                Next
                If fileOK Then
                    Upload2.ContentLength = fileUpload1.PostedFile.ContentLength
                    Upload2.FileName = fileName
                    Upload2.UploadedLength = 0
                    Upload2.IsReady = True
Dim bufferSize As Integer = 1
Dim buffer As Byte() = New Byte(bufferSize - 1) {}
                    Using fs As New FileStream(Path.Combine(HttpContext.Current.Server.MapPath(path__1), fileName), FileMode.Create
                        While Upload2.UploadedLength < Upload2.ContentLength

Dim bytes As Integer = fileUpload1.PostedFile.InputStream.Read(Buffer, 0, bufferSize)
                            fs.Write(buffer, 0, bytes)
                            Upload2.UploadedLength += bytes
                        End While
                    End Using

Const js As String = "onComplete(1,'File uploaded correctly.','{0}','{1} of {2} Bytes');"
                    scriptManager.RegisterStartupScript(Me, GetType(FileUploadFotosPDF), "progress", String.Format(js, fileName, Upload2.UploadedLength, Upload2.ContentLength), True)
                    Session("Enabled") = fileName
                Else

Const js As String = "onComplete(4, 'There was a problem with the file. Perhaps, this file is not an image or corrupt','','0 of 0 Bytes');"
                    scriptManager.RegisterStartupScript(Me, GetType(FileUploadFotosPDF), "progress", js, True)
                End If

                Upload2.IsReady = False
            Else
Const js As String = "onComplete(4,'No file has been selected.','','0 of 0 Bytes');"
                scriptManager.RegisterStartupScript(Me, GetType(FileUploadFotosPDF), "progress", js, True)

Visual basic button if query

This is probably very simple, but I need a button to appear if another button is clicked. I am using Visual studio.

This is the process:

  1. If this button is clicked: 'cmdUpdateBooking'
  2. This button will appear: 'cmdUpdate'

Sorry to ask a very simple question. A coded example would be helpful.

ASP.NET FileUpload Not working

The issue is very straightforward. Two days ago everything was working just fine but today, my FileUpload asp control doesn't work. I've made several researches but I haven't seen a code or explanation that solves my problem. This is the code I have.

I will summarize, If you need more code just ask it, I will provide it.

HTML:

<td style="text-align: left;"><asp:FileUpload id="FileUpload1" runat="server" /></td>

The FileUpload is inside a table as you can see nothing more to explain. (I am not using AJAX since I saw that the FileUpload doesn't work with AJAX without some code).

Vb.net:

ruta = ConfigurationManager.AppSettings.Get("RutaFotosDirecciones").ToString()



    id_foto = (DateTime.Now - New DateTime(1970, 1, 1)).TotalMilliseconds / 1000
    Dim path As String = Server.MapPath(ruta)
    Dim fileOK As Boolean = False
    If FileUpload1.HasFile Then
        Dim fileExtension As String
        fileExtension = System.IO.Path. _
            GetExtension(FileUpload1.FileName).ToLower()
        Dim allowedExtensions As String() = _
            {".jpg", ".jpeg", ".png", ".gif"}
        For i As Integer = 0 To allowedExtensions.Length - 1
            If fileExtension = allowedExtensions(i) Then
                fileOK = True
            End If
        Next
        If fileOK Then
            Try
                FileUpload1.PostedFile.SaveAs(path & id_foto & fileExtension)
            Catch ex As Exception
            End Try
        End If
    End If

I am using the Web.config file to set up my path.

The FileUpload1.HasFIle returns false and doesn't enter the if.

Thanks in advance.

How to add columns and data to treeviewadv of aga.controls

Private Class ColumnNode
    Inherits Node
    Public nodeControl11 As String = "" ' This sould make the DataPropertyName specified in the Node Collection.
    Public nodeControl21 As String = ""
    Public nodeControl31 As String = ""
    Public Sub New(ByVal nodeControl1 As String, ByVal nodeControl2 As String, ByVal nodeControl3 As String)
        nodeControl11 = nodeControl1
        nodeControl21 = nodeControl2
        nodeControl31 = nodeControl3
    End Sub
End Class


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

    Dim col1 As String = "All Parent"

    Dim col2 As String = "Parent"
    Dim col3 As String = "All "
    Dim mmodel As TreeModel = New TreeModel()

    TreeViewAdv1.UseColumns = True

    Dim nodeControl11 As TreeColumn = New TreeColumn("Matcode", 100)
    Dim nodeControl21 As TreeColumn = New TreeColumn("Title", 200)
    Dim nodeControl31 As TreeColumn = New TreeColumn("Ref", 150)

    TreeViewAdv1.Model = mmodel
    TreeViewAdv1.Columns.Add(nodeControl11)
    TreeViewAdv1.Columns.Add(nodeControl21)
    TreeViewAdv1.Columns.Add(nodeControl31)

    Dim ntb As NodeTextBox = New NodeTextBox()
    ntb.DataPropertyName = "Text"
    ntb.ParentColumn = nodeControl11
    Dim ntb1 As NodeTextBox = New NodeTextBox()
    ntb1.DataPropertyName = "Text"
    ntb1.ParentColumn = nodeControl21
    Dim ntb2 As NodeTextBox = New NodeTextBox()
    ntb2.DataPropertyName = "Text"
    ntb2.ParentColumn = nodeControl31

    TreeViewAdv1.NodeControls.Add(ntb)
    TreeViewAdv1.NodeControls.Add(ntb1)
    TreeViewAdv1.NodeControls.Add(ntb2)
    For i = 0 To 20
        'Dim parentnode As Node = New Node("phild" & i.ToString.Trim)

        Dim parentnode As ColumnNode = New ColumnNode(col1, col2, col3)



        mmodel.Nodes.Add(parentnode)

        For j = 0 To 2
            ' Dim childnode As Node = New Node("child" & j.ToString.Trim)
            Dim childnode As ColumnNode = New ColumnNode(col3, col1, col2)


            parentnode.Nodes.Add(childnode)


        Next j

    Next i


    TreeViewAdv1.Visible = True

End Sub

The above code is what I have converted from C# to vb.net, displayed in the link below how to add items to TreeViewAdv in multi-column mode with winforms

However, it is not producing the desired result. What change shall made in the code to add data for each column and display it in the treeviewAdv?

I am getting +/- and lines, which compels me to anticipate that nodes are created but not displayed.

Any suggestion with a working model please?

VB.NET best practice for applications running for a long time?

I have made an application in vb.net that can sometimes take several hours to finish up, and i have noticed that it will quite often crash while waiting for some processes to finish.

For example:

My app uses Form.Show() to open 3 other forms that are needed in the process of the app. These forms can sometimes take several hours to finish, while they are running, my mainform is inactive, and just waiting for form.formclosing() events to happen, at which point it will then execute clean up codes and exit the app. My problem is, that when the forms that my maincode spawns closes, it sometimes crashes the app with a "System.Reflection.TargetInvocationException" error in the windows log files. I know where it crashes, i just dont know how to prevent it from crashing at this point.

So on mainform.load() i have addhandlers for the forms:

AddHandler Form1.FormClosing, AddressOf Form1Closed
AddHandler Form2.FormClosing, AddressOf Form2Closed

And Boolean Dims for later:

Dim F1Closed As Boolean = False
Dim F2Closed As Boolean = False

The app then displays the forms:

Public sub StartForms()
    form1.Show()
    form2.Show()
end sub

and thats the end of that sub, and the mainform then goes on standby until:

Public Sub Form1Closed()

        F1Closed = True

        If F2Closed = True Then
            CloseApp()
        End If

    End Sub
Public Sub Form2Closed()

    F2Closed = True

    If F1Closed = True Then
        CloseApp()
    End If

End Sub

And my close code:

Public Sub CloseApp()
    Try

        For i As Integer = System.Windows.Forms.Application.OpenForms.Count - 1 To 1 Step -1

            Dim form As Form = System.Windows.Forms.Application.OpenForms(i)

            form.Dispose()
        Next i
    Catch ex As Exception
    Finally
        Me.Dispose()

        Environment.Exit(0)
    End Try
End Sub

During the Form1.FormClosing or Form2.FormClosing, the app just crashes with the invocation error as above.

I cant get any more detail on it, even with a try..catch in the events.

Any help would be much appreciated..

Items not showing in listbox

I've got a simple list box on my VB form and I'm adding strings to it using the standard lstBox.items.add("string") command. However, the items aren't actually showing up in the list box. If I iterate through the items collection using:

For each item in lstBox.items
   msgbox(item)
next

It shows up just fine as part of the collection. It just isnt visible in the list box. If I add items to said collection before compilation, using the IDE, they show up fine and I can delete them in the normal way. I have tried deleting and re-adding it but that hasn't helped.

Quite frankly I am stumped, because I have used listboxes hundreds of times and I can't get this to work. So any help would be appreciated.

Thanks in advance

Javascript code cached in browser

I have a below inline Javascript code in my aspx page of asp.net web application.

 function Confirm_Popup(dealid) {
 var bVal
 bVal = confirm("Are you sure you want to assign the same deal again?");
 if (!bVal)
    window.location.href = "page.aspx?id=" + id;
else
    window.location.href = "page1.aspx?id=" + id; 
}

I am calling the code from code behind file like below.

ScriptManager.RegisterStartupScript(Me.Page, Me.GetType(), "showalert", "Confirm_Popup('" & Id & "');", True)

Step 1: Open the the page link for the first time.

Step 2: Open the same link again in new tab.

Issue is I am getting confirm Pop up in Step 1 but Step 2 is not giving pop up. Requirement is to display pop up in step 1&2. It seems like code is cached by browser.

Kindly help.

Harder For Crackers

I'm writing my school work about software cracking (software piracy) and Im making example crackme application (in Visual Basic). Currently Im using these methods as crack protection: 1 - Application code is obfuscated and binary is packed. 2 - Application must run only from Launcher (if you run it directly error will appear) 3 - Launcher is obfuscated and packed too. 4 - License key (hash) is written in registry (encrypted by MD5) 5 - On start application download file with valid license keys and compare license key from registry with this file (if licensed key is not in file with valid keys application will crash) (after comparation is downloaded file deleted) 6 - On start application download file with license key expiration date and compare it with date from cumputer (after comparation is downloaded file deleted) I know it can not be completely protected from crackers (it will be cracked). Do you have other anti piracy tricks and tips? Thank you :)

Permit free scrolling in xceed grid vb.net

I use a GridControl in Xceed.Grid in vb.net.

In my grid, the rows' height are specified by some timespan information.

I would like to permit the user to scroll into this grid, but the problem is that every time you scroll once in the grid, you scroll until the beginning of the next row.

I would like to know if it's possible to scroll a definite height in the grid when you scroll with your mouse.

I search in the properties of the gridcontrol but I didn't manage to find any property that handle this problem.

VB.net if else convert to case select

hi guys can you help me to convert this to case select statement, this is my first time using case select statement.

If TabControl1.SelectedTab Is tp_5 Then
      myqry = "SELECT * FROM TBLVLAN5 ORDER BY ID"
ElseIf TabControl1.SelectedTab Is tp_7 Then
      myqry = "SELECT * FROM TBLVLAN7 ORDER BY ID"

i search in web but i only found case select statement using integer and string and not the one that fit with my if else example.

i also try use it but its not working, this is my code.

Dim h As String
    h = TabControl1.SelectedTab Is tp_10
    Select Case h
        Case TabControl1.SelectedTab Is tp_5
            myqry = "SELECT * FROM TBLVLAN5 ORDER BY ID"
        Case TabControl1.SelectedTab Is tp_7
            myqry = "SELECT * FROM TBLVLAN7 ORDER BY ID"
        Case TabControl1.SelectedTab Is tp_8
            myqry = "SELECT * FROM TBLVLAN8 ORDER BY ID"
    End Select

any help is greatly appreciated. thanks.

How to use a checkbox to change values in an SQL database in asp.net

I currently have system which has a web front end and a back office system. User can book properties online or call our office to book a property. In the admin system on the web front, I have two check boxes to determine if the property is available on the front end or the back office system. This is controlled using a Check box. The code for the check box is as follows;

<asp:CheckBox ID="CheckBoxAvailableToWeb" runat="server" TextAlign="Left" Text="Available for web bookings"
                                    Checked="true" />

I have an field in an SQL Database called "isAvailableToWeb" which has a Boolean result. What I want to achieve is if the check box is checked, the value of the "isAvailableToWeb" field is set to "True" or set to "False" if un-checked.

I have tried to complete this function using the following code;

 Protected Sub CheckBoxAvailableToWeb_CheckedChanged(sender As Object, e As EventArgs, ByVal beachhutid As Long)
    Using dbContext = New bbhasDBEntities
        Dim item
        item = (From i In dbContext.tblBeachHuts Where i.beachHutId = beachhutid Select i).First()
        If CheckBoxAvailableToWeb.Checked = True Then

            item.AvailableToWeb = True
        Else
            item.AvailableToWeb = False
        End If

        dbContext.tblBeachHuts.Attach(item)
        Call dbContext.SaveChanges()
    End Using
End Sub

This code doesn't throw up any errors but doesn't also make the change that I would like to see.

I have a button on this page that saves the information so I would also like to know if it would be better, once the code is working, to put it in that Sub.

Which events are raised when a form is showned after it was hiding (vb.net)

In my vb.net project, I navigate between forms. I have a main form in which I can display new forms and modify some information in them.

When I closed these new forms, the main form, previously hidden, is displayed by the form.show() method and should consider these modifications.

In order to do that I need to know which event(s) is(are) raised when a form is shown by the form.show() method.

I already try to use the form.show event but it is only raised when the form is firstly showned at the start.