小编Bra*_*don的帖子

List(of String)或Array或ArrayList

希望对大多数具有一定经验的程序员来说是个简单的问题.

什么是允许我这样做的数据类型?

Dim lstOfStrings as *IDK*

Dim String0 As String = "some value"
Dim String1 As String = "some value"
Dim String2 As String = "some value"
Dim String3 As String = "some value"
Dim String4 As String = "some value"
Dim String5 As String = "some value"


lstOfStrings.add(String0, String1, String2, String3)
Run Code Online (Sandbox Code Playgroud)

我会像这样访问这些

Dim s1 = lstOfStrings(0)
Dim s2 = lstOfStrings(1) 
Dim s3 = lstOfStrings(2) 
Dim s4 = lstOfStrings(3)
Run Code Online (Sandbox Code Playgroud)

如果我使用List(of String)我只能在列表中添加一个东西(一次),并且在我的函数中我希望能够存储多个值(一次).

解:

Private Function Foo() As List(Of String)


    Dim temp1 …
Run Code Online (Sandbox Code Playgroud)

vb.net collections list

23
推荐指数
2
解决办法
17万
查看次数

File.Create()之后"另一个进程正在使用文件"

我有一个应用程序,如果该文件尚不存在,则会创建一个文本文件,然后向其写入内容.当我创建并立即写入文件时,它第一次工作得很好.我的问题是,下次执行此代码并且文件已经创建时,它会在我尝试写入文件时抛出异常.我得到"文件被另一个进程使用"错误.

所以我创建它之后似乎需要关闭文件?我不知道怎么做,但它可能非常简单.我会发布一些代码,但它不是必需的,我只是使用一个香草味的字符串构建器和流编写器.

    Private Sub createFileLocations()
        If Not Directory.Exists("./Path") Then
            Directory.CreateDirectory("./Path")
        End If
        If clsGeneralSettings.Printer1 IsNot Nothing Then
            If Not File.Exists("./Path/File1" & ".txt") Then
                File.Create("./Path/File1" & ".txt")
            End If
        End If
    End Sub


Private Sub AppendTextFile(randomId As String, PrintDate As Date, PrintName As String)
    Try
        Dim _stringBuilder As StringBuilder = New StringBuilder
        Dim _StreamWriter As StreamWriter
        Dim fileName As String
        If PrintName = clsGeneralSettings.Printer1 Then
            fileName = "./Path/File1" & ".txt"
            qPrinter1.Enqueue(randomId)
            If qPrinter1.Count > 10 Then
                qPrinter1.Dequeue()
            End If
             _stringBuilder.AppendLine(PrintDate + …
Run Code Online (Sandbox Code Playgroud)

.net vb.net io stringwriter

7
推荐指数
1
解决办法
2万
查看次数

打印前使用 WPF 窗口作为可视化模板

我正在制作一个用于打印标签的 WPF 应用程序。我想设计一个标签模板作为 WPF 窗口。在另一个类中,我将实例化这个“窗口模板”,在运行时填充属性并打印标签。我无法在打印前在屏幕上显示标签,因此无法在此窗口实例上调用 .ShowDialog()。这在后面发挥作用。

过去一周我一直在做这方面的研究,我发现了两种几乎可以分别做我想做的事情的方法,如果我可以将它们结合起来就可以了,但是我遗漏了一部分。

可以让它工作,但按照这里的步骤 在 WPF 第 2 部分中打印

这样就完成了打印文档的基本操作。但是,我将无法使用我的模板,我必须将所有内容放在后面的代码中。这是一个可行的选择,但我想更多地探索模板的想法。

        PrintDialog pd = new PrintDialog();
        FixedDocument document = new FixedDocument();
        document.DocumentPaginator.PageSize = new System.Windows.Size(pd.PrintableAreaWidth, pd.PrintableAreaHeight);

        FixedPage page1 = new FixedPage();
        page1.Width = document.DocumentPaginator.PageSize.Width;
        page1.Height = document.DocumentPaginator.PageSize.Height;


        // add some text to the page
        Label _lblBarcode = new Label();
        _lblBarcode.Content = BarcodeConverter128.StringToBarcode(palletID);
        _lblBarcode.FontFamily = new System.Windows.Media.FontFamily("Code 128");
        _lblBarcode.FontSize = 40;
        _lblBarcode.Margin = new Thickness(96);
        page1.Children.Add(_lblBarcode);


        // add the page to the document
        PageContent page1Content = …
Run Code Online (Sandbox Code Playgroud)

c# wpf templates

5
推荐指数
1
解决办法
2723
查看次数

VB.NET Select Case - 正确的陈述是什么?

为什么以下代码不起作用?

Private Function resolveSiteName(ByVal plantName As String, ByVal siteName As String) As Integer
    Dim siteId As Integer = Nothing
    Dim fullName As String = plantName & siteName
    Select Case fullName
        Case fullName.Contains("Example" And "Example2" And "Example3")
            siteId = 0
    End Select
    Return siteId
End Function
Run Code Online (Sandbox Code Playgroud)

我猜我Select Case fullName错了,因为在调试它时,条件得到满足,它只是跳过分配siteId.

我也试过这个

Case fullName.Equals("Exactly what full name is")
Run Code Online (Sandbox Code Playgroud)

只是为了测试看看它是否会起作用......它仍然会跳过分配部分.

我在这里错过了什么?

vb.net select-case

2
推荐指数
1
解决办法
9699
查看次数

在 VB.net 中添加两个不同的日期,而不使用“现在”

我一直在浏览这里和其他网站上的一堆不同的帖子,以将两个日期加在一起,但出于某种原因,每个人都想使用“现在”

我想知道如何在现在都不是的情况下将两个不同的日期加在一起!

我已经尝试了一些东西,但我遇到了铸造错误。另外值得注意的是,我将其设置为页面上日期时间选择器的值。

MaxDate.Value = MinDate.Value + TimeSpan.FromDays(1)
'does not work 
MaxDate.Value = Now + TimeSpan.FromDays(1)
'does work!
Run Code Online (Sandbox Code Playgroud)

如果它不明显,我的页面上有两个日期选择器,当单击单选按钮时,我想将“结束日期”(maxdate.value)设置为“开始日期”(mindate.value)的任何值,并且添加一天。

谢谢您的帮助!

vb.net datetime

1
推荐指数
1
解决办法
1908
查看次数

读取文本文件显示到控制台然后附加文本文件

我有一个名字的文本文件.我想将文本文件读入流中,将其显示到控制台.完成后,它将提示用户输入他们的名字.然后它应该将它添加到文件中.

我可以让它分开做这两件事而不是一起做.这是我的代码.

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>

using namespace std;
using namespace System;

int main(array<System::String ^> ^args)
{
 fstream myfile;
 string line;
 string name;
    myfile.open("Names.txt",ios::out | ios::in | ios_base::app);
    if (myfile.is_open())
    { 
      while( getline(myfile, line) )
      {
          cout << line << endl;
      }
     cout << "Enter your name!\n";
     getline (cin, name);
     myfile << name;
     myfile.close();
 }
 else
 {
     cout << "file was not opened\n";
 }

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

如果我将while循环留在那里,它会将所有名称写入控制台,但不会将用户输入的名称附加到列表中.如果我取出while循环,我可以为文件添加一个名称,但当然我没有得到该文件中已有的名称列表.

我最好的猜测是,我认为这可能与以下事实有关:在使用getline循环浏览文件后,位置位于我的流的末尾,所以当我尝试为其添加名称时,没有'在流中留下的任何房间?

c++ file-io iostream

1
推荐指数
1
解决办法
767
查看次数

C#递归增量递减不能用作参数

我正在使用递归将两个数字加在一起,方法是一次将1加到第一个输入,直到达到第二个的值。为什么这项工作...

        private static int AddMethod(int input1, int input2)
    {
        if (input2 == 0)
        {
            Console.WriteLine(input1);
            return (input1);
        }
        else
        {
            input1++;
            input2--;
            return AddMethod(input1, input2);
        }

    }
Run Code Online (Sandbox Code Playgroud)

但是不是这个

    private static int AddMethod(int input1, int input2)
    {
        if (input2 == 0)
        {
            Console.WriteLine(input1);
            return (input1);
        }
        else
        {
            return AddMethod(input1++, input2--);
        }

    }
Run Code Online (Sandbox Code Playgroud)

我正在使用Visual Studio 2010和.Net 4.0

c# recursion increment

-2
推荐指数
1
解决办法
824
查看次数